【发布时间】:2020-01-29 15:27:08
【问题描述】:
我目前正在使用 vue-router 来管理我项目的不同 Vue。
我的 main.js
import Vue from 'vue'
import App from './App.vue'
import jQuery from 'jquery'
import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.css'
global.jQuery = jQuery
global.$ = jQuery
import './assets/css/animate.css'
import router from './router'
import store from './vuex'
Vue.config.productionTip = false
new Vue({
store,
router,
render: h => h(App)
}).$mount('#app')
当我第一次在仪表板 ('/dashboard') 上时,会调用 'created' 方法。从 API 中检索数据并显示在我的数组中。
之后,我单击数组中的一个元素,该元素将我路由到“/details/:id”(其中 id 是我的元素的 id)。一切正常,然后我单击“返回”按钮。
我在仪表板页面上再次完成,我看到再次调用了“创建”方法,从 API 中很好地检索了数据,但 什么都没有显示,我的数组保持为空。
我真的不明白为什么。
有'created'函数的代码:
export default {
created: function() {
console.log('created => dashboard');
let store = this.$store;
let q = this.rows;
//get rows
if (store.state.socket.io._callbacks["$rows"] == undefined) {
console.log("Binding rows");
//Where I receive the rows from API
store.state.socket.io.on("rows", data => {
console.log("rows reponse:", data);
if (data.success) {
this.nbrItems = data.rows.length;
q.splice(0, q.length); //Clean the array without replacing the instance
data.rows.map(a => q.push(a));
console.log("Queue length: " + q.length);
}
});
}
//get the queue
this.refresh(); // This send a request to the API to ask it to send us back the datas
},
我使用this.$router.go(-1) 导航回“/dashboard”页面。
编辑:是否存在状态问题或类似问题?我不明白为什么,因为在内存中我可以访问所有数据,只是不再有绑定......
【问题讨论】:
标签: vue.js vue-router