javascript - vuex 參數(shù)綁定問題求解
問題描述
組件中參數(shù)的定義像如下寫的這樣
<script>import store from ’../vuex/store’;export default { // vuex: { // actions: actions, // getters: { // // 過濾后的會(huì)話列表 // sessions: ({ sessions, filterKey }) => { // let result = sessions.filter(session => session.user.name.includes(filterKey)); // return result; // }, // // 當(dāng)前會(huì)話index // currentId: ({ currentSessionId }) => currentSessionId // } // }, data(){return { sessions: store.state.sessions, currentId: store.state.currentSessionId} }, methods:{selectSession(id){ console.log(id); store.dispatch(’selectSession’, id)} }};</script><template><p class='list'> <ul><li v-for='item in sessions' : @click='selectSession(item.id)'> <img:alt='item.user.name' :src='http://www.intensediesel.com/wenda/item.user.img'> <p class='name'>{{item.user.name}}</p></li> </ul></p></template>
其中sessions的定義能不能雙向綁定呢, 我發(fā)現(xiàn)selectSession 方法執(zhí)行的時(shí)候, sessions并沒有改變,是不是哪里沒有寫對(duì)呢。
問題解答
回答1:vuex 官方文檔不是這么綁定數(shù)據(jù)的哦,數(shù)據(jù)監(jiān)聽放在 computed里面,而不是直接放在 data 的方法里面,而且 vuex 對(duì)表單的雙向處理是這樣子的。
//來自 vuex 官方例子<input v-model='message'>// jscomputed: { message: { get () { return this.$store.state.obj.message }, set (value) { this.$store.commit(’updateMessage’, value) } }}
希望對(duì)你有幫助~~~
相關(guān)文章:
1. MySQL客戶端吃掉了SQL注解?2. php自學(xué)從哪里開始?3. mysql - AttributeError: ’module’ object has no attribute ’MatchType’4. 數(shù)據(jù)庫 - MySQL 單表500W+數(shù)據(jù),查詢超時(shí),如何優(yōu)化呢?5. 求大神幫我看看是哪里寫錯(cuò)了 感謝細(xì)心解答6. python - Django分頁和查詢參數(shù)的問題7. javascript - 圖片能在網(wǎng)站顯示,但控制臺(tái)仍舊報(bào)錯(cuò)403 (Forbidden)8. javascript - 百度echarts series數(shù)據(jù)更新問題9. phpstady在win10上運(yùn)行10. python小白的基礎(chǔ)問題 關(guān)于while循環(huán)的嵌套
