vue组件动态化demo

Former-commit-id: dd8ca6bb6731e5a50b72c4416cf7f731cb84317c
Former-commit-id: 9b9c6cbd63a5db44a0ea74b88cd3d79e033a25b6
TSXN
wanggang 5 years ago
parent ba4816833d
commit ebbe16a7ee

@ -98,11 +98,15 @@ namespace UserCenter.Areas.Admin.Controllers
}
if (this.Repo.ReadOnlyTable().Any(o => o.Email == model.Email))
{
ModelState.AddModelError(o => model.UserName, "邮箱已经存在");
ModelState.AddModelError(o => model.Email, "邮箱已经存在");
}
if (!string.IsNullOrEmpty(model.PhoneNumber) && this.Repo.ReadOnlyTable().Any(o => o.PhoneNumber == model.PhoneNumber))
{
ModelState.AddModelError(o => model.Email, "手机号已经存在");
}
if (this.Repo.ReadOnlyTable().Any(o => o.NickName == model.NickName))
{
ModelState.AddModelError(o => model.UserName, "昵称已经存在");
ModelState.AddModelError(o => model.NickName, "昵称已经存在");
}
return base.Add(model);
}

@ -0,0 +1,30 @@
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"library": "axios@0.19.2",
"destination": "wwwroot/lib/axios"
},
{
"library": "pubsub-js@1.8.0",
"destination": "wwwroot/lib/pubsub-js",
"files": ["pubsub.min.js"]
},
{
"library": "vue@2.6.11",
"destination": "wwwroot/lib/vue",
"files": [ "vue.min.js" ]
},
{
"library": "vue-router@3.2.0",
"destination": "wwwroot/lib/vue-router",
"files": [ "vue-router.min.js" ]
},
{
"library": "vuex@3.2.0",
"destination": "wwwroot/lib/vuex",
"files": [ "vuex.min.js" ]
}
]
}

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>loading</title>
</head>
<body>
<div id="app">
<router-view class="view"></router-view>
</div>
<script src="lib/axios/axios.min.js"></script>
<script src="lib/pubsub-js/pubsub.min.js"></script>
<script src="lib/vue/vue.min.js"></script>
<script src="lib/vuex/vuex.min.js"></script>
<script src="lib/vue-router/vue-router.min.js"></script>
<script src="js/index.js"></script>
</body>
</html>

@ -0,0 +1,67 @@
//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');

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1 @@
!function(r){"use strict";var n={};r.PubSub=n;var t=r.define;!function(a){"use strict";var c={},e=-1;function i(r){var n;for(n in r){if(r.hasOwnProperty(n)){return true}}return false}function o(n){return function r(){throw n}}function f(r,n,t){try{r(n,t)}catch(r){setTimeout(o(r),0)}}function s(r,n,t){r(n,t)}function u(r,n,t,e){var i=c[n],o=e?s:f,u;if(!c.hasOwnProperty(n)){return}for(u in i){if(i.hasOwnProperty(u)){o(i[u],r,t)}}}function p(e,i,o){return function r(){var n=String(e),t=n.lastIndexOf(".");u(e,e,i,o);while(t!==-1){n=n.substr(0,t);t=n.lastIndexOf(".");u(e,n,i,o)}}}function l(r){var n=String(r),t=Boolean(c.hasOwnProperty(n)&&i(c[n])),e=n.lastIndexOf(".");while(!t&&e!==-1){n=n.substr(0,e);e=n.lastIndexOf(".");t=Boolean(c.hasOwnProperty(n)&&i(c[n]))}return t}function t(r,n,t,e){r=typeof r==="symbol"?r.toString():r;var i=p(r,n,e),o=l(r);if(!o){return false}if(t===true){i()}else{setTimeout(i,0)}return true}a.publish=function(r,n){return t(r,n,false,a.immediateExceptions)},a.publishSync=function(r,n){return t(r,n,true,a.immediateExceptions)},a.subscribe=function(r,n){if(typeof n!=="function"){return false}r=typeof r==="symbol"?r.toString():r;if(!c.hasOwnProperty(r)){c[r]={}}var t="uid_"+String(++e);c[r][t]=n;return t},a.subscribeOnce=function(r,n){var t=a.subscribe(r,function(){a.unsubscribe(t);n.apply(this,arguments)});return a},a.clearAllSubscriptions=function r(){c={}},a.clearSubscriptions=function r(n){var t;for(t in c){if(c.hasOwnProperty(t)&&t.indexOf(n)===0){delete c[t]}}},a.countSubscriptions=function r(n){var t;var e=0;for(t in c){if(c.hasOwnProperty(t)&&t.indexOf(n)===0){e++}}return e},a.getSubscriptions=function r(n){var t;var e=[];for(t in c){if(c.hasOwnProperty(t)&&t.indexOf(n)===0){e.push(t)}}return e},a.unsubscribe=function(r){var n=function(r){var n;for(n in c){if(c.hasOwnProperty(n)&&n.indexOf(r)===0){return true}}return false},t=typeof r==="string"&&(c.hasOwnProperty(r)||n(r)),e=!t&&typeof r==="string",i=typeof r==="function",o=false,u,f,s;if(t){a.clearSubscriptions(r);return}for(u in c){if(c.hasOwnProperty(u)){f=c[u];if(e&&f[r]){delete f[r];o=r;break}if(i){for(s in f){if(f.hasOwnProperty(s)&&f[s]===r){delete f[s];o=true}}}}}return o}}(n),"function"==typeof t&&t.amd?t(function(){return n}):"object"==typeof exports&&(void 0!==module&&module.exports&&(exports=module.exports=n),exports.PubSub=n,module.exports=exports=n)}("object"==typeof window&&window||this);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,22 @@
<template>
<h2>{{title}}</h2>
</template>
<script>
({
data: function(){
return {
title: '首页',
token:null
}
},
mounted: function () {
document.querySelector('title').innerHTML = this.title;
this.token = PubSub.subscribe('msg', function (msg, data) {
alert(msg + data);
});
},
beforeDestroy: function () {
PubSub.unsubscribe(this.token);
}
});
</script>

@ -0,0 +1,16 @@
<template>
<h2>{{title}}</h2>
</template>
<script>
({
data: function (){
return {
title: '登录',
token:null
}
},
mounted: function () {
document.querySelector('title').innerHTML = this.title;
}
});
</script>
Loading…
Cancel
Save