成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

淺談vuex的基本用法和mapaction傳值問題

vuex的理論知識就不多提了,官網(wǎng)上已經(jīng)有明確的講解。

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比漠河網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式漠河網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋漠河地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。

用一個簡單的例子來描述一下基本的用法:

第一步:npm install vuex –save-dev

第二步:在目錄中創(chuàng)建store目錄配置管理狀態(tài)

//store/index.js
/**
 * Created by zhaohuan on 2017/7/13.
 */
import Vue from 'vue'
import Vuex from 'vuex';


Vue.use(Vuex);

const store = new Vuex.Store({
 state: {
  msg: '原始數(shù)據(jù)'
 },
 actions: {
  fun: function ({commit},date) {
   commit('saveAdminInfo', {list: date});
  },
 },
 mutations: {
  saveAdminInfo(state, adminInfo){
   state.msg = adminInfo.list;
  }
 }
});


export default store;

第三步:在main.js中引入store

new Vue({

 el: '#app',
 router,
 store,
 template: '<App/>',
 components: { App }
});

第四部:編寫路由頁面

//test1.vue
<template>
 <div>
 msg:{{msg}}

  <input type="text" v-model="checkedNames" >
  <button @click="fun">提交</button>
 </div>


</template>

<script>
 import {mapState,mapActions} from 'vuex';
 export default{
  data(){
    return{
     checkedNames:''
    }
  } ,
  computed: {...mapState(['msg'])},
  methods: {
//    ...mapActions(['fun']);
//如果需要向actions里面?zhèn)髦稻褪謩诱{(diào)用
fun(){
     this.$store.dispatch('fun',this.checkedNames);
   }
 //...mapActions(['fun'])==   this.$store.dispatch('fun');
  }
 }
</script>

test2.vue

<template>
 <div>
  msg:{{msg}}
 </div>
</template>

<script>
 import {mapState} from 'vuex';
 export default{
  computed: {...mapState(['msg'])}, //對應(yīng)getters.技術(shù)中的msg
//  methods: {...mapActions(['fun'])}
 }
</script>

修改之前:

test1

淺談vuex的基本用法和mapaction傳值問題

test2

淺談vuex的基本用法和mapaction傳值問題

以上這篇淺談vuex的基本用法和mapaction傳值問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持創(chuàng)新互聯(lián)。

名稱欄目:淺談vuex的基本用法和mapaction傳值問題
轉(zhuǎn)載注明:http://jinyejixie.com/article20/jjjsjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站策劃、網(wǎng)站排名、ChatGPT響應(yīng)式網(wǎng)站、全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)
法库县| 永仁县| 彭山县| 法库县| 蓬莱市| 内黄县| 泰州市| 汾阳市| 永年县| 阿图什市| 昌平区| 珲春市| 南江县| 舟山市| 舟山市| 奉节县| 雷州市| 绥滨县| 沿河| 平顶山市| 图们市| 东兰县| 克什克腾旗| 海伦市| 正阳县| 凤翔县| 柯坪县| 左权县| 保靖县| 治多县| 元朗区| 溧阳市| 万源市| 桂阳县| 赤水市| 泽库县| 山东| 故城县| 翼城县| 西青区| 阿城市|