亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于list組件點擊到info組件詳情中報錯 state is not defined,如果刪去store.commit(),不報錯但又顯示全部列表內容

List.vue

<template>

<div>

?<ul>

? <li v-for="(item, index) in pageLists"

? ?:key = "index"

? ?@click="more(index)"

>

? ? {{index}} - {{ item.title }} - {{ item.content }}

? ?</li>

? ?</ul>

</div>

</template>


<script>

import store from '@/store'

export default {

name:'list',

store,

methods: {

? ?more(index){

? ? ? store.commit('detail', index)

? ? ?this.$router.push('/info')

}

},

computed: {

? ? pageLists(){

? ? ? return store.state.lists

? ? ?}

? ?},

}

</script>

<style scoped>

</style

Info.vue

<template>

<div>

? ?<div v-for="(item, index) in pageLists"

? ? ? ? ? ?:key="index"

? ? ? ? ? v-show="index == current">

? ? ? ?<span>{{item.title }}</span>

? ? ? ?<p>{{ item.content }}</p>

? ?</div>

</div>

</template>

<script>

import store from '@/store'

export default {

? ?name:'info',

? ?store,

? ?data(){

? ?return {

? ? }

? ?},

? computed:{

? ?pageLists(){

? ? ? ?return store.state.lists

? ?},

? ?current(){

? ? ?return store.state.number

? }

}

}

</script>

<style scoped>

</style>

store.js

import Vue from 'vue';

import Vuex from 'vuex';

Vue.use(Vuex)


export default new Vuex.Store({

? ? ?state: {

? ? ? ? ?lists:[],

? ? ? ? number:null

? ? ?},

? ?mutations: {

? ? ? addList(state, value){

? ? ? ? ?state.lists.push(value)

? ? ?},

? ? detail(index){

? ? ? state.number = index

? ?}

},

actions: {


},

});



正在回答

1 回答

我覺得是你store.js里面,detail方法沒有接受 state 作為第一個參數:

detail(state,index){

? ? ? state.number = index

}

vuex-mutations你可以看一下文檔


1 回復 有任何疑惑可以回復我~
#1

淡水狗 提問者

謝謝,是的。是漏了這個參數。已經解決
2019-05-07 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

關于list組件點擊到info組件詳情中報錯 state is not defined,如果刪去store.commit(),不報錯但又顯示全部列表內容

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號