簡體   English   中英

如何在 vue-class 中為 v-model 使用計算屬性?

[英]How to use computed properties in vue-class for v-model?

我想將 v-model 用於帶有 vuex 的 vuedraggable 插件,但我不知道如何在@Component裝飾器中設置如下所示的計算屬性。 對此有其他解決方案嗎?

computed: {
  myList: {
    get() {
      return this.$store.state.Goal.goalData.steps
    },
    set(value) {
      this.$store.dispatch('sortList', {id: this.$store.state.Goal.goalId, list:value})
    }
  }
}

<draggable v-model='myList'></draggable>

你會這樣做:

<template>
  <div>
    <input v-model="computedMsg">
  </div>
</template>

<script>
import Vue from 'vue'
import Component from 'vue-class-component'

@Component({
  props: {
    propMessage: String
  }
})
export default class App extends Vue {

  // computed
  get computedMsg () {
    return state.val
  }

  set computedMsg (val) {
    return store.commit("changeVal", val)
  }
}
</script>

請記住,您需要調整上面的代碼以適合您的特定應用程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM