3
我VUE組分是這樣的:如何更新vuex中的狀態? vue.js 2
<template>
<div>
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label for="status" class="sr-only">Status</label>
<select class="form-control" v-model="selected" @change="filterByStatus()">
<option value="">All Status</option>
<option v-for="status in orderStatus" v-bind:value="status.id">{{ status.name }}</option>
</select>
</div>
</div>
</div>
...
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex';
export default {
...
data() {
return { selected: '' }
},
methods: {
filterByStatus: function() {
this.$store.state.status = this.selected
}
}
}
</script>
我的模塊訂購vuex是這樣的:
import { set } from 'vue'
import order from '../../api/order'
import * as types from '../mutation-types'
const state = {
status: ''
}
const getters = {
...
}
const actions = {
...
}
const mutations = {
...
}
export default {
state,
getters,
actions,
mutations
}
我使用此:this.$store.state.order.status = this.selected
,當被執行時,更新的狀態,但存在着像這樣的錯誤:
[Vue warn]: Error in callback for watcher "function() { return this._data.$$state }": (found in)
Error: [vuex] Do not mutate vuex store state outside mutation handlers.
我該如何解決它?
我想更新的狀態,因爲我想通過組件使用的值的另一