You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/WebMVC/wwwroot/js/index.js

68 lines
1.8 KiB

//functions
function parseModel(name, response) {
var html = new DOMParser().parseFromString(response.data, 'text/html');
var template = html.getElementsByTagName('template')[0].innerHTML;
var script = html.getElementsByTagName('script')[0].innerHTML + '//# sourceURL=' + name;
var model = eval(script);
model.template = template;
return model;
}
//vuex
Vue.use(Vuex);
const store = new Vuex.Store({
state: {
accessToken: localStorage.getItem("accessToken"),
refreshToken: localStorage.getItem("refreshToken")
}
});
//vue route
const routes = [
];
var routeList = routes.concat();
const router = new VueRouter({
routes
});
router.beforeEach((to, from, next) => {
//if (!store.state.accessToken && to.path !== '/pages/login.html') {
// router.push('/pages/login.html');
// return;
//}
var route;
for (var i = 0; i < routeList.length; i++) {
if (routeList[i].path === to.path) {
route = routeList[i];
}
}
if (!route) {
var url = to.path === '/' ? '/pages/home.html' : to.path;
var name = url.replace(/\//g, "-").replace(/\./g, "-").substring(1);
var route = {
path: to.path,
component: Vue.component(name, function (resolve, reject) {
axios.get(url).then(function (response) {
resolve(parseModel(name, response));
});
})
};
router.addRoutes([route]);
routeList.push(route);
router.push(to.path);
}
else {
next();
}
});
//app
const app = new Vue({
store: store,
router,
data: {
},
mounted: function () {
console.log('mounted:app');
setTimeout(function () {
PubSub.publish('msg','data');
}, 5000)
}
}).$mount('#app');