|
@@ -1,13 +1,25 @@
|
|
|
<template>
|
|
|
<div id="app">
|
|
|
<h2>路由</h2>
|
|
|
- <!-- 跳转路由标签 => a标签 -->
|
|
|
- <h3>跳转标签</h3>
|
|
|
- <router-link to="/home">去首页</router-link>
|
|
|
- <!-- 占位显示 -->
|
|
|
- <h3>显示位置</h3>
|
|
|
+ <!-- 跳转路由标签 => a标签 -->
|
|
|
+ <h3>跳转标签</h3>
|
|
|
+ <div class="nav">
|
|
|
+ <!-- <router-link active-class="active" to="/home"
|
|
|
+ >去首页</router-link
|
|
|
+ > -->
|
|
|
+ <router-link active-class="active" :to="{name:'home'}"
|
|
|
+ >去首页</router-link
|
|
|
+ >
|
|
|
+ <router-link active-class="active" to="/list"
|
|
|
+ >去列表</router-link
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ <!-- 占位显示 -->
|
|
|
+ <h3>显示位置</h3>
|
|
|
+ <div class="main">
|
|
|
<router-view></router-view>
|
|
|
- <hr>
|
|
|
+ </div>
|
|
|
+ <hr />
|
|
|
<h2>Vuex</h2>
|
|
|
<!--
|
|
|
State:
|
|
@@ -18,16 +30,16 @@
|
|
|
<p>1.名字{{ name1 }},来自{{ address1 }}</p>
|
|
|
<p>2.名字{{ $store.state.name }},来自{{ $store.state.address }}</p>
|
|
|
<p>3.名字{{ name }},来自{{ address }}</p>
|
|
|
- <hr>
|
|
|
+ <hr />
|
|
|
<!--
|
|
|
Getters
|
|
|
1.this.$store.getters.xxx 在生命周期,或者适当的方法中
|
|
|
2.$store.getters.xxx 在template模板中
|
|
|
3.引入mapGetters 在computed中 ...mapGetters(['xxx']
|
|
|
-->
|
|
|
- <p>1.数值:{{count1}}</p>
|
|
|
- <p>2.数值:{{$store.getters.newCount}}</p>
|
|
|
- <p>2.数值:{{newCount}}</p>
|
|
|
+ <p>1.数值:{{ count1 }}</p>
|
|
|
+ <p>2.数值:{{ $store.getters.newCount }}</p>
|
|
|
+ <p>2.数值:{{ newCount }}</p>
|
|
|
<hr />
|
|
|
<!--
|
|
|
Mutations 同步
|
|
@@ -50,7 +62,7 @@
|
|
|
使用:this.xxx()
|
|
|
-->
|
|
|
<button @click="add">添加</button>
|
|
|
- <br><br>
|
|
|
+ <br /><br />
|
|
|
<button @click="reduce">递减</button>
|
|
|
<h2>组件库</h2>
|
|
|
<el-button type="primary">主要按钮</el-button>
|
|
@@ -90,9 +102,9 @@ export default {
|
|
|
this.address1 = this.$store.state.address;
|
|
|
this.count1 = this.$store.getters.newCount;
|
|
|
},
|
|
|
- computed:{
|
|
|
- ...mapState(['name','address']),
|
|
|
- ...mapGetters(['newCount'])
|
|
|
+ computed: {
|
|
|
+ ...mapState(["name", "address"]),
|
|
|
+ ...mapGetters(["newCount"]),
|
|
|
},
|
|
|
methods: {
|
|
|
init() {
|
|
@@ -117,24 +129,24 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
add() {
|
|
|
- this.$store.commit("addCount",10);
|
|
|
+ this.$store.commit("addCount", 10);
|
|
|
},
|
|
|
// 同步
|
|
|
// ...mapMutations(['reduceCount']),
|
|
|
// 异步
|
|
|
- ...mapActions(['asyncReduce']),
|
|
|
+ ...mapActions(["asyncReduce"]),
|
|
|
reduce() {
|
|
|
// 同步
|
|
|
// this.reduceCount();
|
|
|
// this.$store.commit("reduceCount");
|
|
|
// 异步
|
|
|
- this.$store.dispatch("asyncReduce")
|
|
|
+ this.$store.dispatch("asyncReduce");
|
|
|
// this.asyncReduce()
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
-<style lang="scss">
|
|
|
+<style lang="scss" scoped>
|
|
|
.el-carousel__item h3 {
|
|
|
color: #475669;
|
|
|
font-size: 18px;
|
|
@@ -150,4 +162,22 @@ export default {
|
|
|
.el-carousel__item:nth-child(2n + 1) {
|
|
|
background-color: #d3dce6;
|
|
|
}
|
|
|
+.active {
|
|
|
+ color: red;
|
|
|
+ padding: 20px;
|
|
|
+ border: 1px solid #000;
|
|
|
+}
|
|
|
+.nav {
|
|
|
+ width: 500px;
|
|
|
+ height: 100px;
|
|
|
+ border: 1px solid plum;
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-around;
|
|
|
+ align-items: center;
|
|
|
+}
|
|
|
+.main {
|
|
|
+ width: 800px;
|
|
|
+ height: 800px;
|
|
|
+ border: 1px solid yellowgreen;
|
|
|
+}
|
|
|
</style>
|