在iview中ajax返回值如何赋值上层变量?

        authorlist: 1
    },
    methods: {
        handleSearchauthor: function(value) {
                    $.ajax({  
                       url : 'post1.php',  
                       type : 'post',  
                       data : value,  
                       success : function(data) { 
                       在这个地方,我怎么把data赋给authorlist呢?
阅读 3.9k
3 个回答
handleSearchauthor: function (value) {
    let self = this;
    $.ajax({
        ...,
        success: function (data) {
            self.authorlist = data;
        }
    })
}

`authorlist: 1

},
methods: {
    handleSearchauthor: function(value) {
                var   _self   =   this
                $.ajax({  
                   url : 'post1.php',  
                   type : 'post',  
                   data : value,  
                   success : function(data) { 
                     _self.authorlist  =  data
                  }

`
self.属性名 指向实例的数据

箭头函数

        authorlist: 1
    },
    methods: {
        handleSearchauthor: function(value) {
                    $.ajax({  
                       url : 'post1.php',  
                       type : 'post',  
                       data : value,  
                       success : (data) => { 
                           this.authorlist = data