Commit 1004db6e by 姜雷

修改页签可以卸载页面store

parent a67f6841
{
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": true,
"arrowParens": "avoid",
"requirePragma": false,
"proseWrap": "preserve"
}
...@@ -4,42 +4,67 @@ ...@@ -4,42 +4,67 @@
<template slot="nav"> <template slot="nav">
<sidebar-nav :routers="route" /> <sidebar-nav :routers="route" />
</template> </template>
<router-view></router-view> <router-view v-if="routerDone" />
<div
class="loading-container"
v-else
v-loading="!routerDone"
></div>
</app-layout> </app-layout>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: "app", name: 'app',
created() { created() {
console.log(this.route); console.log(this.route);
}, },
props: { props: {
route: { route: {
type: Array, type: Array,
default: () => [] default: () => [],
} },
}, },
data() { data() {
let dataList = []; let dataList = [];
for (let index = 0; index < 20; index++) { for (let index = 0; index < 20; index++) {
dataList[index] = { dataList[index] = {
id: index, id: index,
name: "asdad" name: 'asdad',
}; };
} }
return { return {
routerDone: false,
filters: {}, filters: {},
dataList: dataList, dataList: dataList,
selectVal: "", selectVal: '',
pagination: { pagination: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
total: 123 total: 123,
} },
}; };
} },
mounted() {
this.showComponents();
},
watch: {
$route(newVal) {
this.routerDone = false;
if (newVal.meta && newVal.meta.store) {
newVal.meta.store.install(this.$store);
}
this.showComponents();
},
},
methods: {
showComponents() {
this.$nextTick(vm => {
this.routerDone = true;
});
},
},
}; };
</script> </script>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"name": "rym-element-ui", "name": "rym-element-ui",
"version": "0.1.16", "version": "0.1.17",
"description": "任意门组件库", "description": "任意门组件库",
"main": "lib/rymUi.common.js", "main": "lib/rymUi.common.js",
"scripts": { "scripts": {
......
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
</template> </template>
<script> <script>
import Vue from "vue"; import Vue from 'vue';
import SidebarItem from "./SidebarItem"; import SidebarItem from './SidebarItem';
import ScrollBar from "@/components/ScrollBar"; import ScrollBar from '@/components/ScrollBar';
import { Menu, MenuItem, Submenu } from "element-ui"; import { Menu, MenuItem, Submenu } from 'element-ui';
import ImgIcon from "../ImgIcon/ImgIcon"; import ImgIcon from '../ImgIcon/ImgIcon';
// import { constantRouterMap } from "../../../../router/index.js"; // import { constantRouterMap } from "../../../../router/index.js";
Vue.component(Menu.name, Menu); Vue.component(Menu.name, Menu);
Vue.component(Submenu.name, Submenu); Vue.component(Submenu.name, Submenu);
...@@ -29,16 +29,16 @@ Vue.component(MenuItem.name, MenuItem); ...@@ -29,16 +29,16 @@ Vue.component(MenuItem.name, MenuItem);
Vue.component(ImgIcon.name, ImgIcon); Vue.component(ImgIcon.name, ImgIcon);
export default { export default {
name: "sidebar-nav", name: 'sidebar-nav',
components: { components: {
SidebarItem, SidebarItem,
ScrollBar ScrollBar,
}, },
props: { props: {
routers: { routers: {
type: Array, type: Array,
default: () => [] default: () => [],
} },
}, },
watch: { watch: {
$route(newRoute, oldRoute) { $route(newRoute, oldRoute) {
...@@ -47,18 +47,18 @@ export default { ...@@ -47,18 +47,18 @@ export default {
oldRoute.matched[0].name || oldRoute.matched[0].path oldRoute.matched[0].name || oldRoute.matched[0].path
); );
} }
} },
}, },
computed: { computed: {
isCollapse() { isCollapse() {
return this.$route.matched.length === 2; return this.$route.matched.length === 2;
} },
} },
}; };
</script> </script>
<style lang="scss"> <style lang="scss">
@import "../../assets/styles/variables.scss"; @import '../../assets/styles/variables.scss';
.sidebar-container { .sidebar-container {
transition: width 0.28s; transition: width 0.28s;
width: $sideBar-width; width: $sideBar-width;
...@@ -152,6 +152,7 @@ export default { ...@@ -152,6 +152,7 @@ export default {
font-size: 12px; font-size: 12px;
} }
.el-menu-item { .el-menu-item {
color: #fff !important;
text-align: left; text-align: left;
&:hover { &:hover {
background-color: $menuHover !important; background-color: $menuHover !important;
...@@ -197,8 +198,9 @@ export default { ...@@ -197,8 +198,9 @@ export default {
position: relative; position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
color: #fff !important;
&::after { &::after {
content: ""; content: '';
position: absolute; position: absolute;
z-index: 2; z-index: 2;
bottom: -5px; bottom: -5px;
...@@ -216,7 +218,6 @@ export default { ...@@ -216,7 +218,6 @@ export default {
} }
&.is-opened { &.is-opened {
.el-submenu__title { .el-submenu__title {
color: #fff !important;
background-color: $subMenuBg !important; background-color: $subMenuBg !important;
&::after { &::after {
opacity: 1; opacity: 1;
......
...@@ -32,38 +32,38 @@ ...@@ -32,38 +32,38 @@
</template> </template>
<script> <script>
import ScrollPane from "../ScrollPane"; import ScrollPane from '../ScrollPane';
import { mapGetters, mapActions } from "vuex"; import { mapGetters, mapActions } from 'vuex';
import store from "./store.js"; import store from './store.js';
export default { export default {
name: "tags-views", name: 'tags-views',
components: { ScrollPane }, components: { ScrollPane },
created() { created() {
store.install(); store.install(this.$store);
}, },
data() { data() {
return { return {
visible: false, visible: false,
top: 0, top: 0,
left: 0, left: 0,
selectedTag: {} selectedTag: {},
}; };
}, },
computed: { computed: {
...mapGetters(["visitedViews"]) ...mapGetters(['visitedViews']),
}, },
watch: { watch: {
$route() { $route() {
this.addViewTags(); this.addViewTags();
this.moveToCurrentTag(); this.moveToCurrentTag();
} },
}, },
mounted() { mounted() {
this.addViewTags(); this.addViewTags();
}, },
methods: { methods: {
...mapActions(["addVisitedViews", "delVisitedViews"]), ...mapActions(['addVisitedViews', 'delVisitedViews']),
generateRoute() { generateRoute() {
if (this.$route.name) { if (this.$route.name) {
return this.$route; return this.$route;
...@@ -78,7 +78,6 @@ export default { ...@@ -78,7 +78,6 @@ export default {
if (!route) { if (!route) {
return false; return false;
} }
if (route.meta.store) route.meta.store.install();
this.addVisitedViews(route); this.addVisitedViews(route);
}, },
moveToCurrentTag() { moveToCurrentTag() {
...@@ -93,19 +92,19 @@ export default { ...@@ -93,19 +92,19 @@ export default {
}); });
}, },
closeSelectedTag(view) { closeSelectedTag(view) {
if (view.store) view.store.uninstall(); if (view.store) view.store.uninstall(this.$store);
this.delVisitedViews(view).then(views => { this.delVisitedViews(view).then(views => {
if (this.isActive(view)) { if (this.isActive(view)) {
const latestView = views.slice(-1)[0]; const latestView = views.slice(-1)[0];
if (latestView) { if (latestView) {
this.$router.push(latestView.path); this.$router.push(latestView.path);
} else { } else {
this.$router.push("/"); this.$router.push('/');
} }
} }
}); });
} },
} },
}; };
</script> </script>
......
import TagsViewStore from './TagsView.js'; import TagsViewStore from './TagsView.js';
export default { export default {
install() { install(store) {
const store = window[Symbol.for('vueAppStore')]; console.log(store);
if (!store.state.app) { if (!store.state.app) {
store.registerModule(['app'], { store.registerModule(['app'], {
...@@ -13,8 +13,7 @@ export default { ...@@ -13,8 +13,7 @@ export default {
store.registerModule(['app', 'tagsView'], TagsViewStore); store.registerModule(['app', 'tagsView'], TagsViewStore);
} }
}, },
uninstall() { uninstall(store) {
const store = window.$store;
store.unregisterModule(['app', 'tagsView']); store.unregisterModule(['app', 'tagsView']);
}, },
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment