【问题标题】:Vue composition api not working, data not set with the extracted data from the dabaseVue 组合 api 不起作用,未使用从数据库中提取的数据设置数据
【发布时间】:2021-07-01 09:11:13
【问题描述】:

尝试使用 Vue 3 组合 API 来编写一些更好的代码,但我无法让它像我想要的那样工作。我无法使用数据库中的值更新值。

// component part
<template>
    <SomeChildComponent :value="settings"/>
</template>

// script part
<script>
import { ref, onMounted} from 'vue'
export default {
setup() {

    let settings = ref({
      active : 1,
      update : 0,
      ...
    })

    // this wont change the values
    const getSettingsValues = async () => {  
          const response = await axios.get('/api/settings')// works

          settings.active.value = response.data.active;//undefined
          settings.update.value = 1;//undefined (even with hardcoded value)
          [and more]

     }
     getSettingsValues()

     return { settings };
}
}
</script>

【问题讨论】:

    标签: vue.js vuejs3 vue-composition-api


    【解决方案1】:

    当您使用 ref 属性时,您将字段 value 放错了位置,它应该是:

    settings.value.active= response.data.active;
    settings.value.update= 1
    

    【讨论】:

      猜你喜欢
      • 2019-12-15
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 2014-06-09
      • 2021-10-28
      相关资源
      最近更新 更多