选项Api和组合Api的组合使用,关于变量范围的问题。Combined use of options and combinations, questions about variable scope. #7046
Replies: 4 comments 3 replies
-
您好,关于vue3+sfc 如果使用sfc语法糖 + 普通的script选项式Api 我发现在选项式api中打印this将抛出异常Cannot convert object to primitive value,无论是否包含sfc。 |
Beta Was this translation helpful? Give feedback.
-
@yyx990803 尤大佬, 麻烦解答下呗。 |
Beta Was this translation helpful? Give feedback.
-
defineExport 是什么东西?你难道说的是defineexpose? |
Beta Was this translation helpful? Give feedback.
-
expose details |
Beta Was this translation helpful? Give feedback.
-
Hello, about vue3+sfc
Use the option API, including the setup function. If the setup returns the value of {xxx:'Xiao Ming'} through return, it can be called through this.xxx in other life cycles.
If you use sfc syntax sugar + normal script option Api
SFC syntax sugar exposes the xxx variable through defineExpose, and cannot be called through this.xxx or xxx in the option api. Here sfc syntactic sugar and setup function have a functional deviation, am I not finding the right way?
I found out that printing this in option-style api will throw exception Cannot convert object to primitive value, with or without sfc.
Beta Was this translation helpful? Give feedback.
All reactions