zoukankan      html  css  js  c++  java
  • mutations.js文件书写规范及模板调用此文件书写方法

    1)mutations.js代码如下

    const mutations={
        add(state){
            state.count++
        },
        reduce(state){
            state.count--
        }
    }
    

     2)在button中,通过commit直接调用。

    <button @click="$store.commit('add')">+</button>
    <button @click="$store.commit('reduce')">-</button>
    

     放在组件home.vue中案例代码

    <template>
      <div class="Home">
        <button @click="$store.commit('add')">+</button>
        <button @click="$store.commit('reduce')">-</button>
    
        <p>引用state选项一个变量:{{count}}</p>
        </div>
    </template>
    <script>
    export default {
      name: 'Home',
      data () {
        return {
          msg: 'Home.vue 组件'
        }
      },
      computed: {
        // 调用是vuex,state选项文件rootState.js中声明变量
        count () {
          console.log('this结构:' + this.$store.state.count)
          return this.$store.state.count
        }
      }
    }
    </script>
    
    做产品的程序,才是好的程序员!
  • 相关阅读:
    J2EE第四周
    J2EE 第三周
    jsf简单入门
    Applrt和Ajax
    hello.java分析
    filter用户例子
    分析LogFilter
    理解session
    关于XML
    企业级应用和互联网应用的区别
  • 原文地址:https://www.cnblogs.com/asplover/p/11355279.html
Copyright © 2011-2022 走看看