【发布时间】:2018-06-03 20:10:37
【问题描述】:
我得到 ajax 响应
{ pid: 6, status: true }
我需要存储 pid 并在下一个 ajax 发布请求中传递它。
我目前的vue js如下
submitBox = new Vue({
el: "#submitBox",
data: {
name: '',
gstno: '',
about: '',
pid: '',
},
methods: {
handelSubmit: function(e) {
var vm = this;
data = {};
data['name'] = this.name;
data['gstno'] = this.gstno;
data['about'] = this.about;
$.ajax({
url: 'alpha/add/post/',
data: data,
type: "POST",
dataType: 'json',
success: function(e) {
if (e.status) {
alert(" Success")
} else {
vm.response = e;
alert(" Failed")
}
}
});
return false;
}
},
});
我需要将pid 存储为全局变量,并为所有ajax 请求使用相同的变量。我怎样才能做到这一点?
【问题讨论】:
-
当你说“存储”时,你的意思是把结果存储在
Vue之外的某个地方吗?? -
vue 本身没有?如果能够在另一个 vue 中使用它会更好..
-
哦...你最好使用
Vue components和Vuex,如果你要存储的数据只会被其他Vues使用。
标签: javascript jquery vue.js vuejs2 vue-component