在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
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进