0

Here is my vuejs component:

<script>
export default {
    props: ['columns', 'records', 'group', 'users'],
    data: function () {
        return {
            new_record: true,
            myrecords: this.records
        }
    },
    methods: {
        addRow: function () {
            try {
                console.log(this.myrecords);
                this.myrecords.push({});
                console.log(this.myrecords);
            } catch (e) {
                console.log(e);
            }
        },
        saveRow: function () {
            $.post("http://localhost/someurl", { somedata: somevalue })
                .done(function (data) {
                    console.log(data);
                    this.addRow();
                })
                .fail(function (error) {
                    console.log(error);
                    alert("error");
                });
...
...

Error: app.js:155 Uncaught TypeError: this.addRow is not a function

I understood why this happens, because this in current context is jquery object,

but question is how do I call addRow method of my vue component?

1 Answer 1

3

You need add let self = this before call ajax. Then, you can call self.AddRow()

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

Comments

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.