vuejs / composition-api

Composition API plugin for Vue 2
https://composition-api.vuejs.org/
MIT License
4.19k stars 342 forks source link

setup返回的data在development环境下会被expose到全局mixin的data中 #988

Closed AuSjukwa closed 1 year ago

AuSjukwa commented 1 year ago

复现: https://codesandbox.io/s/friendly-glade-v3dn8m?file=/src/main.js

// main.js
const globalData = { bar: '' };
Vue.mixin({
    data: () => globalData,
});

// child.vue
export default {
    setup() {
        const foo = ref('foo');
        return { foo };
    }
}

child组件渲染后打印globalData,globalData中会有foo变量

AuSjukwa commented 1 year ago

https://github.com/vuejs/composition-api/blob/main/src/mixin.ts

solution

// child.vue
export default {
    data() {
        return {};
    },
    setup() {
        const foo = ref('foo');
        return { foo };
    }
}

在使用setup的组件加上一个空的data

github-actions[bot] commented 1 year ago

Stale issue message