Javascript 导出默认属性数据中的vuex状态。。。可能吗?

Javascript 导出默认属性数据中的vuex状态。。。可能吗?,javascript,vue.js,button,state,vuex,Javascript,Vue.js,Button,State,Vuex,我想为我在项目的各个部分中使用的按钮设置属性,因此我不能在每个按钮中插入静态文本,但我尝试使用vuex的状态,因此如果我必须更改名称,我只会在所有按钮的状态中更改,而不是通过在每个按钮中查找来更改。 这个解决方案对我不起作用,因为按钮中没有显示任何内容,而是应该显示“Foo”和“Bar”字样(事实上,我希望它们出现在我面前)。实际上,它不接受btnType属性 这是我的一个组件: <template> <div> <b-button v-fo

我想为我在项目的各个部分中使用的按钮设置属性,因此我不能在每个按钮中插入静态文本,但我尝试使用vuex的状态,因此如果我必须更改名称,我只会在所有按钮的状态中更改,而不是通过在每个按钮中查找来更改。 这个解决方案对我不起作用,因为按钮中没有显示任何内容,而是应该显示“Foo”和“Bar”字样(事实上,我希望它们出现在我面前)。实际上,它不接受
btnType
属性

这是我的一个组件:

 <template>
  <div>
     <b-button
    v-for="(btn, idx) in buttons"
    :key="idx"
    :class="btn.class"
    variant="info"
    :name="btn.btnType"
    >{{ btn.btnType }}</b-button
   >
  </div>
 </template>

 <script>
 import { mapState, mapMutations } from "vuex";
  export default {
   computed: {
     ...mapState({
       buttonFoo: "buttonFoo",
       buttonBar: "buttonBar",
     }),
   },

   data() {
     return {
       buttons: [
         {
           btnType: this.buttonFoo,
           state: true,
           class: "button-class1",
         },
         {
           btnType: this.buttonBar,
           state: false,
           class: "button-class2",
         },
       ],
     };
   },
 };
 </script>

数据在计算属性之前求值,因此无法访问数据中的计算属性

最好在
mounted

export default {
   computed: {
     ...mapState({
       buttonFoo: "buttonFoo",
       buttonBar: "buttonBar",
     }),
   },

   data() {
     return {
       buttons: []
     };
   },
   mounted(){
    this.buttons=[
         {
           btnType: this.buttonFoo,
           state: true,
           class: "button-class1",
         },
         {
           btnType: this.buttonBar,
           state: false,
           class: "button-class2",
         },
       ],
   }
 };

数据在计算属性之前求值,因此无法访问数据中的计算属性。是否有解决方案?如果我尝试将mapState加载到已创建的而不是已计算的中,它能工作吗?TOP!:-)这正是我想要的,塔克斯
export default {
   computed: {
     ...mapState({
       buttonFoo: "buttonFoo",
       buttonBar: "buttonBar",
     }),
   },

   data() {
     return {
       buttons: []
     };
   },
   mounted(){
    this.buttons=[
         {
           btnType: this.buttonFoo,
           state: true,
           class: "button-class1",
         },
         {
           btnType: this.buttonBar,
           state: false,
           class: "button-class2",
         },
       ],
   }
 };