如何<script setup>在 vue 中訪問計算屬性?我檢查了檔案,但它甚至沒有提到如何在里面定義計算屬性<script setup>,我只是從https://stackoverflow.com/a/71459106/2311074得到的
那么給定下面的代碼,如何訪問url里面的計算屬性<script setup>?
<script setup>
import {computed} from 'vue';
const url = computed(() => 'Hallo');
const printUrl = () => {
// How to access here the computed property url?
this.url // throws TypeError "Cannot read properties of undefined"
url // <- returns an object of ComputedRefImpl instead of 'Hallo'
}
uj5u.com熱心網友回復:
你試過了嗎url.value,計算回傳一個只讀的反應參考物件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/490019.html
