this在各類回呼中使用:
如果是普通函式是沒法使用的
所以需要先將this.變數賦值給新的變數,然后才能在回呼函式中使用
例如:
refund: function (id) {
if (!this.url.refund) {
this.$message.error("請設定url.refund屬性!")
return
}
var that = this;
this.$confirm({
title: "確認退款",
content: "是否要進行退款?",
onOk: function () {
putAction(that.url.refund, { "id": id }).then((res) => {
if (res.success) {
that.$message.success(res.message);
that.loadData();
} else {
that.$message.warning(res.message);
}
});
}
});
},
如果是箭頭函式式可以使用的
下面的這個例子只是參考,并不代表this.$confirm就是這么使用,具體參考ant的檔案
下面的例子只是代表,箭頭函式可以使用this
efund: function (id) {
if (!this.url.refund) {
this.$message.error("請設定url.refund屬性!")
return
}
this.$confirm({
title: "確認退款",
content: "是否要進行退款?",
onOk: () => {
putAction(that.url.refund, { "id": id }).then((res) => {
if (res.success) {
this.$message.success(res.message);
this.loadData();
} else {
this.$message.warning(res.message);
}
});
}
});
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/150726.html
標籤:JavaScript
上一篇:ES6中Set和WeakSet
