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>
これは機能します!本当にありがとう! 突然変異がbtw - >に設定されていましたが、なんらかの理由で正しく機能しませんでした。 –
@ NathanielDeshpandeこれが正しい答えとして受け入れることを忘れないでください。あなたがより良い答えを見つけた場合は、それを投稿してください。 – qw3n