日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vuex的使用二

發布時間:2023/12/2 vue 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vuex的使用二 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.先看項目的目錄結構

2.在main.js里需要引入store這個文件并掛在實例上

import store from './store/store' ............new Vue({el: '#app',router,store,template: '<App/>',components: { App } })

3.store.js里引入action.js和mutation.js文件

// 狀態管理器 import Vue from 'vue' import Vuex from 'vuex' import actions from './action' import mutations from './mutation' Vue.use(Vuex)const store = new Vuex.Store({state : {author: 'Wise Wrong',amsg: '',},actions,mutations,getters:{author(state){console.log(state)return state.author}} }) export default store

4.action.js

import * as types from './mutation_type' export default{newAuthor({commit},bData){commit(types.NEWAUTHOR,bData);} }

5.mutation.js

import * as types from './mutation_type' export default{[types.NEWAUTHOR](state,msg){state.author=msg;} }

6.mutation_type.js

export const SEND_A="SEND_A" export const NEWAUTHOR="NEWAUTHOR"

7.head.vue

temple: <form class="navbar-form navbar-left"><div class="form-group"><input type="text" v-model="inputTxt" class="form-control" placeholder="通過input改變author"></div><button type="button" class="btn btn-default" @click="setAuthor">Submit</button></form>script:data () {return {inputTxt:""}},methods:{setAuthor: function () {this.$store.dispatch("newAuthor", this.inputTxt);}}

8.foot.vue

<p>Copyright&nbsp;&copy;&nbsp;author:{{author}} - 2016 All rights reserved</p>import { mapGetters} from 'vuex'??computed: {...mapGetters(['author'])}

?9.效果

?

?

轉載于:https://www.cnblogs.com/ldlx-mars/p/7787069.html

總結

以上是生活随笔為你收集整理的vuex的使用二的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。