vuex.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <view class="container">
  3. <u-navbar :is-fixed="false" :border-bottom="false" :is-back="true" back-icon-name="arrow-leftward"
  4. back-icon-color="#fff" back-icon-size="35" :background="{ background: 'linear-gradient(90deg, #69b0ff, #5f88ff)' }" title="Vuex 操作"
  5. title-color="#fff">
  6. </u-navbar>
  7. <view class="u-demo">
  8. <view class="u-demo-wrap">
  9. <view class="u-demo-title">演示效果</view>
  10. <view class="u-demo-area u-flex u-row-center">
  11. <!-- vuex已做过封装,可以直接使用state内的变量 -->
  12. 版本号为:{{version}}
  13. </view>
  14. <view class="u-demo-area u-flex u-row-center">
  15. [ BladeX ] 的作者为:{{userInfo.nickName}}
  16. </view>
  17. </view>
  18. <view class="u-config-wrap">
  19. <view class="u-config-title u-border-bottom">参数操作</view>
  20. <view class="u-config-item">
  21. <view class="u-item-title">按钮点击</view>
  22. <u-button @click="modifyVuex">修改变量</u-button>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. methods: {
  31. // vuex已做过封装,可以直接this.$u.vuex(key, value)修改,无需引入
  32. modifyVuex() {
  33. // version不在lifeData,每次刷新会丢失
  34. this.$u.vuex('version', '1.0.1');
  35. // userInfo在lifeData,刷新重启会保留
  36. this.$u.vuex('userInfo.nickName', '翼');
  37. }
  38. },
  39. }
  40. </script>