我这里明明是赋过值的,但页面老是说我没赋值(ajax绝对是执行过了的,在页面加载之前就执行了ajax),是不是vue的数组操作有其他的赋值法?
不要在 success:function() 函数中使用this。
每个function函数(非箭头函数)中都有一个自己的this ,
在 success:function() 函数中的this与外面的this指向的不是同一个对象。
需要把外面的this用变量保存一下。在success:function()函数中用保存的变量代替this
比如
arrListItem(){
let mythis = this;
$.ajax({
type:'POST',
url:'php/hotListItem.php',
success:function(result) {
mythis.rotationDataArr=JSON.parse(result);
},
..............
或者success:改成箭头函数
箭头函数内没有自己的this。如果在箭头函数内使用this,访问的是外层函数的this。
比如
arrListItem(){
$.ajax({
type:'POST',
url:'php/hotListItem.php',
success:(result)=>{
this.rotationDataArr=JSON.parse(result);
},
..............
如有帮助,望采纳!谢谢!
1.先排查页面返回值result是否为空值
2.查看日志,和error
使用es6箭头函数才能用this,不然this是有作用域的