Subscribe on changes!

打包成静态站点后 <script setup> 中定义的属性 <script>中获取不到

avatar
Dec 25th 2021

Version

3.2.26

Reproduction link

github.com

Steps to reproduce

  1. npm install
  2. npm run build
  3. npm run preview
  4. 查看 console

What is expected?

this下能get这些属性

What is actually happening?

undefined


正常开发环境能get到 编译打包成静态站点后都get不到, vite 和 vue cli 都试过了, 都是一样的结果

avatar
Dec 26th 2021

This is because you declared the properties using the setup syntax. Use onMounted() instead and keep only one version of the component: the composition or the setup version. You can still access the ref through this.$refs.ref_form though

avatar
Dec 26th 2021

Why the development environment can get properties, but not after packaging. And there is no prohibition in the documentation to use 2 ways at the same time.