亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Vue 3:如何使用組合 API 正確更新組件 props 值?
P粉951914381
P粉951914381 2024-03-25 18:19:32
0
1
677

我喜歡這個組件:

<template>
  <div>
    <p>Current coords: <strong>{{ coords }}</strong></p>
    <button type="button" @click="updateCoords">
  </div>
</template>
<script>
export default {
  props: {
    coords: {
      type: Array,
      required: true
    }
  },
  setup(props) {
    const updateCoords = () => {
      props.coords = [38.561785, -121.449756]
      // props.coords.value = [38.561785, -121.449756]
    }
    return { updateCoords }
  },
}
</script>

我嘗試使用 updateCoords 方法更新 prop coords 值,但收到錯誤消息:

未捕獲類型錯誤:無法設(shè)置未定義的屬性(設(shè)置 '坐標')

在我的情況下如何正確更新 props 值?

P粉951914381
P粉951914381

全部回復(1)
P粉306523969

道具是只讀的:
https://v3.vuejs.org/guide/component -props.html#one-way-data-flow

如果你想要有兩種方式綁定 props,你需要實現(xiàn) v-model 模式:
https://v3-migration.vuejs.org /break-changes/v-model.html#_3-x-syntax


sssccc
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板