我正在尝试使用 Vue + Vuex + Vue 资源从服务器获取数据。单击按钮时我想点击 Http 请求并以列表格式显示。我这样尝试过。这是我的代码
https://plnkr.co/edit/EAaEekLtoiGPvxkmAtrt?p=preview
// Code goes here
var store = new Vuex.Store({
state: {
Item: []
},
mutations: {
getItems: function (state) {
}
},
actions: {
fetchData:function (context) {
this.$http.get('/data.json', function(v1users)
{
// this.$set('v1_user',v1users);
});
}
}
})
var httprequest = Vue.extend({
"template": '#http_template',
data: function () {
return {
items: store.state.Item
}
},
methods: {
fetchData: function () {
store.dispatch('fetchData')
},
}
})
Vue.component('httprequest', httprequest);
var app = new Vue({
el: '#App',
data: {},
})
; 有更新吗?
最佳答案
尝试使用 Vue.http.get
而不是 this.$http.get
。
Vuex 无法直接从实例访问 $http
。
关于javascript - vue.js如何从服务器获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46024316/