我有一些图表,我想通过单击按钮进行更新。商店中的数据已更改,但UI不会更新。
<div class="graph">
<button class="click" @click="changeUi">Change chart</button>
<canvas id="mix" count="2"></canvas>
<chartjs-line target="mix"></chartjs-line>
<chartjs-bar :option="{legend: { display: false }}"
:labels="mylabels":datasets="mydatasets" target="mix"></chartjs-bar>
</div>
export default {
data(){
return{
mydatasets:[{
data: this.$store.state.data}], //This data i want to change
//data: [20, 50, 20, 41, 26, 15, 20, 10, 29, 5, 33, 55]
methods:{
changeUi(){
this.$store.commit('changeChart')
// I want change by this array [10, 30, 34, 23, 11, 15, 55, 30, 19, 35, 43, 21]
}
}
}
我正在main.js中导入图表:
import 'chart.js'
import 'hchs-vue-charts'
Vue.use(window.VueCharts);
答案 0 :(得分:1)
商店属性应在组件中用作computed
属性,而不是在data()
内部。