1
如何在与VueX集成的同时使用VueJS中的计算属性绑定样式。使用计算属性和VueX进行样式绑定
我遇到的问题是关于我的样式属性在我的VueX Store中发生更改后未更新。
代码示例:
//VueX Store
const store = new Vuex.Store({
\t state : {
\t \t div: [
\t \t \t {
\t \t \t \t offset: 0,
\t \t \t \t width: 1,
\t \t \t \t text : 'Hello World'
\t \t \t },
\t \t \t {
\t \t \t \t offset: 0,
\t \t \t \t width: 1,
\t \t \t \t text : 'Hello World As Well'
\t \t \t }
\t \t ]
}
});
//My component
<template>
\t <div v-bind:style="{ width: width, left: offset}">
\t \t <p>{{text}}</p>
\t </div>
</template>
<script>
export default {
\t \t name: 'divBox',
\t \t computed : {
\t \t \t text : function() {
\t \t \t \t return this.$store.state.div[this.Id].text;
\t \t \t },
\t \t \t width : function() {
\t \t \t \t return this.$store.state.div[this.Id].width;
\t \t \t },
\t \t \t offset : function() {
\t \t \t \t return this.$store.state.div[this.Id].offset;
\t \t \t }
\t \t },
\t \t props : ['Id']
}
</script>
This Works!非常感谢! 我有突变设置BTW - >但由于某些原因,他们不能正常工作。 –
@NathanielDeshpande如果这回答了这个问题,请不要忘记接受它作为正确答案。如果你想出了更好的答案,一定要发布它。 – qw3n