Subscribe on changes!

const vm={error:ref("aaa")} 使用 {{vm.error}} 会多渲染出一对双引号

avatar
Feb 18th 2022

Version

3.2.31

Reproduction link

sfc.vuejs.org/

Steps to reproduce

const vm={error:ref("aaa")} 使用 {{vm.error}} 会多渲染出一对双引号

What is expected?

显示 aaa

What is actually happening?

显示 “aaa”

avatar
Feb 18th 2022

This is expected as you logged a raw Ref, which will run its value through JSON.stringify()

You want to red the ref's value:

{{ vm.error.value }}

The value is not unwrapped because vm is not a reactive object.

avatar
Feb 18th 2022

but vm.error is a reactive object.

avatar
Feb 18th 2022

It's a ref.

vm is not a reactive object, so its contents will not be unwrapped in the template.

So reading vm.error gives you the ref, not "aaa"

avatar
Feb 18th 2022

thank you,i got it