没什么好听名字 2022-07-15 11:13 采纳率: 68.4%
浏览 152
已结题

VUE3 为什么打包后变量就不见了

调试时 打印ctx和proxy都可以正常读取到 num 和testFunc 变量.
然后build 打包后 打印ctx 和proxy num和testFunc都不见了。这个是怎么回事?
测试了vue2写法,是正常的

代码:

<template>
    <div>{{ num }}</div>
    <el-button type="success" size="small" @click="testFunc">点击</el-button>
</template>
<script lang="ts">
import { defineComponent, ref, getCurrentInstance } from "vue";
export default defineComponent({
    name: "testPage",
    setup() {
        const { ctx, proxy } = getCurrentInstance() as any;
        const num = ref(0);
        const testFunc = () => {
            console.log(ctx, proxy);
        };
        return {
            num,
            testFunc,
        };
    },
});
</script>

<style lang="stylus" scoped></style>

点击按钮后 调试时是正常的
调试时的:

img

打包后的:

img

  • 写回答

2条回答 默认 最新

  • 关注

    在 vue3 中, ctx 和 proxy 都是只给 dev 使用的。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月23日
  • 已采纳回答 7月15日
  • 赞助了问题酬金10元 7月15日
  • 创建了问题 7月15日