|
@@ -1,5 +1,30 @@
|
|
|
<template>
|
|
|
<div class="about">
|
|
|
<h1>This is an about page</h1>
|
|
|
+ <h1>{{ $store.state.stateNum }}</h1>
|
|
|
+ <h1>当前页面状态值:{{thisVal}}</h1>
|
|
|
+ <h1>mapState的值:{{stateNum}}</h1>
|
|
|
+ <h1>mapStateStr的值:{{stateStr}}</h1>
|
|
|
+ <button @click="changeFun">changeState</button>
|
|
|
</div>
|
|
|
</template>
|
|
|
+<script>
|
|
|
+import {mapState} from 'vuex';
|
|
|
+export default {
|
|
|
+ methods: {
|
|
|
+ changeFun(){
|
|
|
+ console.log(this.$store.state.stateNum);
|
|
|
+ // this.$store 可以获取当前vuex对象的
|
|
|
+ // 通过commit方法调用store/index.js中mutations中方法
|
|
|
+ // 接收多个参数,第一个是mutations中方法名,第二个开始是传入的参数
|
|
|
+ this.$store.commit("stateNumAdd",10);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed:{
|
|
|
+ ...mapState(['stateNum','stateStr']),
|
|
|
+ thisVal(){
|
|
|
+ return this.$store.state.stateNum
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|