我尝试使用vuex将get请求放在商店中并且输出没有出现,这是我在store.js文件上的状态和getter代码:
state:{
timelines:[]
}
get_request:{
timeReq: function(){
this.$http.get('https://my-project-demo-71d7a.firebaseio.com/posts.json').then(function(data){
return data.json();
}).then(function(data){
var blogsArray = [];
for(let key in data){
data[key].id = key
blogsArray.push(data[key]);
}
state.timelines = blogsArray;
});
}
},
getters: {
getTimeline: state =>{
return state.timelines;
}
}
这是我输出它的计算代码:
timeReq(){
return this.$store.getters.getTimeline;
}
所以,问题是没有错误,结果中没有出现错误
答案 0 :(得分:0)
很难说出不可测试的代码片段会发生什么。我附上link to a fiddle你可以乱搞,看看你是否可以在那里重现你的问题。它模仿HTTP调用。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static List<string> movielist = new List<string>();
private void AddMovie_Click(object sender, EventArgs e)
{
MovieProperty mv = new MovieProperty();
mv.ShowDialog();
}
}
<强> HTML 强>
const store = new Vuex.Store({
state: {
message: "loading..."
},
getters: {
message (state) {
return state.message;
}
},
mutations: {
init(state, payload){state.message = payload;}
},
actions: {
init(context){
setTimeout(
function(){
context.commit('init', 'message from the server');
}, 3000);
}
}
})
new Vue({
store,
el: '#example',
computed: {
message: {
get() {
return this.$store.getters.message
}
}
}
})
store.dispatch("init");