-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Illegal reassignment to import myVar
#1160
Closed
Labels
Comments
I think that is not a correct usage, maybe you want to share a reactive object between parent and child components? // App.vue
<template>
<div>{{ isActive }}</div>
<button @click="isActive = !isActive">change value</button>
<HelloWorld :isActive="isActive" />
</template>
<script setup>
import HelloWorld from "./components/HelloWorld.vue";
import { ref } from "vue";
const isActive = ref(false);
</script> // HelloWorld.vue
<template>
<div>
{{ isActive }}
</div>
</template>
<script setup>
import { defineProps } from "vue";
defineProps({
isActive: Boolean,
});
</script> OR // src/state.js
import { reactive } from "vue"
export default reactive({
isActive: false
}) // src/App.vue
<template>
<div>{{ isActive }}</div>
<button @click="isActive = !isActive">change value</button>
<HelloWorld />
</template>
<script setup>
import HelloWorld from "./components/HelloWorld.vue";
import state from "./state";
import { toRef } from "vue";
const isActive = toRef(state, "isActive");
</script> // src/components/HelloWorld.vue
<template>
<div>
{{ state.isActive }}
</div>
</template>
<script setup>
import state from "../state";
</script> |
Yep i can do it like you say, but i want to use it in this way
In the "doc" we can import value from '.vue' file. So maybe it's a wrong information ? |
This was referenced Dec 1, 2020
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
Hello,
I'm trying to use the new script setup feature, but got an error when i'm trying to compile.
Reproduction
Create a fresh vite app
App.vue
HelloWorld.vue
First question, there a way to use
isActive
in theHelloWorld.vue
template without re-declared itconst isActiveTpl = isActive
?Now the bug.
If i use the imported ref in App.vue, everything works in dev mode. But got an error on compilation. See below.
I can fix with
<button @click="isActive.value = !isActive.value">change value</button>
but, it will work in production but not in dev mode :)Source code
Compiled version
System Info
vite
version: v1.0.0-rc.13vue
version : 3.0.3@vue/compiler-sfc
version : 3.0.3Logs (Optional if provided reproduction)
The text was updated successfully, but these errors were encountered: