码迷,mamicode.com
首页 > 其他好文 > 详细

Vuex学习笔记1

时间:2017-12-12 12:22:08      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:commit   bsp   hello   install   data   .com   from   pos   comm   

npm install vuex --save

 

....../vuex/store.js:

 

import Vuex from ‘vuex‘;

import Vue from ‘vue‘;

Vue.use(vuex);

 

const state = { count:1}

 

const mutations = {

    add(state){

    state.count++;   

    },   

   reduce(state){

    state.count--;   

    }

}

 

export default new Vuex.Store({   state,mutations  });

 

Count.vue

<template>

<div>

<h2>{{msg}}<h2>

<h3>{{$store.state.count}}</h3>

<p>

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

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

</p>

</div>

</template>

 

<script>

import store from ‘@/vuex/store.js‘

export default{

 

data(){

   return {

       msg:"hello vuex"  

    }

},

store

 

}

</script>

 

Vuex学习笔记1

标签:commit   bsp   hello   install   data   .com   from   pos   comm   

原文地址:http://www.cnblogs.com/eret9616/p/8026824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!