How to update data of a VueJS instance from a jQuery AJAX call?

后端 未结 3 1553
悲哀的现实
悲哀的现实 2021-01-01 21:48

I have a VueJS instance with some data :

var vm = new Vue({
    el: \'#root\',
    data: {
        id: \'\',
        name: {
            firstname: \"\", 
           


        
3条回答
  •  再見小時候
    2021-01-01 22:03

    not same scope for this.name

    create_casenr: function(event) {
    // update the full name of user
    $.ajax({
        url: 'http://elk.example.com:9200/users/user/' + this.id
    })
    .done(function(data) {
        console.log(data);
        this.name = data._source;
        this.name.valueset = true;
        console.log(this.name);
    }.bind(this))
    

    add a bind(this)

提交回复
热议问题