首页 > 其他 > 详细

Vuex学习笔记1

时间:2017-12-12 11:41:26      阅读:252      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!