0

I am pretty new to vue.js, so I'm not even sure if what I'm trying to do is possible. I am working on developing a Matrix component that I could then use in other applications. My problem is that I would like for the getIdentity() method to return a new Matrix component with an array passed into it

export default {
  name: 'Matrix',
  props: {
    initRows: Number,
    initColumns: Number,
    initValues: Array
  },
  data () {
    return {
      editable: true,
      contents: [],
      rows: 1,
      columns: 1
    }
  },
  created () {
    ...
  },
  methods: {
    addColumn () {...},
    removeColumn (column) {...},
    addRow () {...},
    removeRow (row) {...},
    getRREF () {...},
    getInverse () {...},
    getIdentity () {
      if (this.rows === this.columns) {
        let tempMtx = [];
        for (let row = 0; row < this.rows; row++) {
          tempMtx[row] = [];
          for (let col = 0; col < this.columns; col++) {
            tempMtx[row][col] = row === col ? 1 : 0;
          }
        }
        return new Matrix({propsData: {initValues: tempMtx}}); // This is the part I can't figure out
      } else {
        throw new Error('Rows and Columns must be equal to get the identity matrix');
      }
    }
  }
}
3
  • How do you want to use a component returned from that method? Commented Oct 22, 2018 at 15:18
  • Well I would want it to be a Matrix object/component that I could then either display to the user or perform operations such as using the getInverse() method or like concatenating two Matrix objects together. I know that in Java it is possible to call a class's constructor from within a method in the class, and I was hoping to get similar behavior here. I tries to do "let MatrixClass = vue.extends(this)", which was returning a vue component but did not have any of the data that should have been in it. Commented Oct 22, 2018 at 15:43
  • I think you might be better served having a Matrix object/class and a component that renders it (accepts a Matrix as a prop). But it sounds like you got yourself working so good job! Commented Oct 22, 2018 at 16:31

1 Answer 1

0

I ended up figuring it out with a bit of help from this article. Except that instead of importing it from another file, I just defined let MatrixConstructor = vue.extend(this.a);

Sign up to request clarification or add additional context in comments.

1 Comment

The constructor definition also needs to be after the export statement

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.