Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Objects between Dependency and Application Usage. 应用和依赖取到不同的对象 #14891

Closed
7 tasks done
kanocence opened this issue Nov 7, 2023 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@kanocence
Copy link

Describe the bug

In APP.vue, a Page.vue(dependencies) component is referenced, and the getData function is executed in both components. This function is used to retrieve an object named data. However, after executing the getData function twice, the obtained data objects are different.The project created with 'Vue-cli' works well.

APP.vue中引用了一个Page.vue(依赖中的)组件,并在两个组件中都执行了名为getData的函数。这个函数用来获取一个名为data的对象。然而,两次执行getData函数后得到的data对象却是不同的。vue-cli创建的项目没有这个问题。

dependencies:

let data = {}

export function setData (val) {
  data = val
}

export function getData () {
  return data
}

dependencies(Page.vue):

<script setup>
import { onMounted } from 'vue';
import { getData, setData } from './util';

onMounted(() => {
  console.log('vite-test-demo', getData());
  setData('vite-test-demo');
  console.log('getData', getData());
})
</script>

<template>
  <div>
    <h1>Page</h1>
  </div>
</template>

my app:

<script setup>
import { onMounted } from 'vue';
import { PageVue, getData, setData } from 'vite-test-demo';

onMounted(() => {
  console.log('vite getData', getData());
  setData('vite');
  console.log('vite getData', getData());
});
</script>

<template>
  <PageVue />
</template>

console:

vite-test-demo {}    ------> page.vue
getData vite-test-demo    ------> page.vue
vite getData {}    ------> app.vue
vite getData vite    ------> app.vue

Reproduction

https://stackblitz.com/edit/vitejs-vite-kj9ua2?file=main.js

Steps to reproduce

pnpm dev

open console

System Info

vite@latest
vue@latest

Used Package Manager

pnpm

Logs

No response

Validations

Copy link

stackblitz bot commented Nov 7, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red
Copy link
Member

Duplicate of #3910

@sapphi-red sapphi-red marked this as a duplicate of #3910 Nov 7, 2023
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2023
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Nov 7, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants