代码大致如下,vue中使用 element-ui的组件 this. a l e r t 会 报 错 误 , 因 于 与 alert会报错误,因于与 alert会报错误,因于与.ajax的回调函数中的this冲突,解决方法是将this. a l e r t 的 t h i s 改 为 v u e 对 象 的 名 称 v m . alert的this改为vue对象的名称 vm. alert的this改为vue对象的名称vm.alert,就可以正常提示了
let vm = new Vue({
el: '#app',
data: function () {
return {
machineIp: ''
}
},
methods: {
selectAllInstances: function () {
$.ajax({
type: "get",
url: url,
data:
{
ip: ip
},
success: function (result) {
this.$alert('请刷新页面重试!', '警告', {
confirmButtonText: '确定',
callback: action => {
window.location.reload();
}
});
}
});
}
}
});