How do you access a computed property inside <script setup>
in vue?
I checked the documentation but it does not even mention how to define computed properties inside <script setup>
, I got that only from https://stackoverflow.com/a/71459106/2311074
So given the below code, how to access the computed property url
inside <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'
}
CodePudding user response:
Did you try with url.value
, computed returns a readonly reactive ref object.