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

use vitejs: reactive cannot define const in script setup #1956

Closed
DebugIsFalse opened this issue Feb 9, 2021 · 0 comments
Closed

use vitejs: reactive cannot define const in script setup #1956

DebugIsFalse opened this issue Feb 9, 2021 · 0 comments

Comments

@DebugIsFalse
Copy link

DebugIsFalse commented Feb 9, 2021

Describe the bug

when i use setup in script, will not work
template

<div class="attrs-item">
    <div class="todo-wrapper">
        <div class="todo-write">
            <input type="text" v-model="todoValue" @keypress.enter="addToDoList">
        </div>
        <div class="todolist-drop">
            <div class="todolist-drop-item" v-for="it in todoList" :key="it.id">
                {{it.value}}
            </div>
        </div>
    </div>
</div>

javascript

<script lang="ts" setup>
import { reactive, ref, unref} from 'vue';
interface todoItem {
    status: number,
    value: any,
    id: number
}
const todoValue = ref();
const todoList:Array<todoItem> = reactive([]);
const addToDoList = function(){
    const item = {
        status: 1,
        id: Math.random(),
        value: unref(todoValue)
    }
    todoList.push(item);
    console.log(todoList, '===todoList')
}
</script>

Reproduction

it work in 2.0.0-beta.66
if change
const todoList:Array<todoItem> = reactive([]);
to
let todoList:Array<todoItem> = reactive([]);
the code will run;
and if the code run in setup function also run normal

System Info

  • vite version: 2.0.0-beta.66
  • Operating System: mac OS
  • Node version: v12.18.2
  • Package manager (npm/yarn/pnpm) and version:

Logs (Optional if provided reproduction)

[Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next
at <ToDoList onVnodeUnmounted=fn ref=Ref< {} > >
at
at
[Vue error]: Uncaught (in promise) TypeError: Cannot read property 'type' of undefined

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.