Blame view

pages/template/global/global.vue 1.5 KB
4b045f7c   刘淇   江阴初始化项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  <template>
  	<view class="pa">
  		<view class="uni-divider">
  			<view class="uni-divider__content">globalData</view>
  			<view class="uni-divider__line"></view>
  		</view>
  		<text class="text">globalData中text的值: {{gd.test}}</text>
  		<button @click="setGD()" class="button">修改上述值为123</button>
  
  		<view class="uni-divider">
  			<view class="uni-divider__content">vuex</view>
  			<view class="uni-divider__line"></view>
  		</view>
  		<text class="text">vuex中hasLogin的值: {{testvuex}}</text>
  		<button @click="setVUEX(true)" class="button">修改上述值为true</button>
  		<button @click="setVUEX(false)" class="button">修改上述值为false</button>
  	</view>
  </template>
  
  <script>
  	import {
  		mapState,
  		mapMutations
  	} from 'vuex'
  	export default {
  		data() {
  			return {
  				gd:{}
  			}
  		},
  		computed: {
  			...mapState(['testvuex'])
  		},
  		methods: {
  			...mapMutations(['setTestTrue']),
  			...mapMutations(['setTestFalse']),
  			setGD:function () {
  				this.gd.test="123"
  			},
  			setVUEX:function (isTrue) {
  				// console.log("this.testvuex: " + this.testvuex);
  				// this.hasLogin = true; 这样赋值不生效,必须用store/index.js里注册的mapMutations才行
  				if(isTrue){
  					this.setTestTrue(this.$store.state);
  				}
  				else{
  					this.setTestFalse(this.$store.state);
  				}
  				// console.log("this.testvuex: " + this.testvuex);
  			}
  		},
  		onShow() {
  			this.gd = getApp().globalData
  		}
  	}
  </script>
  
  <style>
  .button {
  	margin: 30rpx;
  	color: #007AFF;
  }
  .text{
  	margin-left: 30rpx;
  }
  </style>