vuejs / composition-api

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

why setup run twice in vue2 #970

Closed zhoufanglu closed 1 year ago

zhoufanglu commented 1 year ago

i install @vue/composition-api at vue 2.6。

xiaoxiangmoe commented 1 year ago

Can you provide me a reproduction demo?

zhoufanglu commented 1 year ago

Can you provide me a reproduction demo?

sorry, this is company project, rather old, later i use vue2 syntax

alexdeia commented 1 year ago

I have the same problem with vue 2 and composition api. But in onMounted hook code runs once.

houcheng commented 1 year ago

Is there any progress on this issue? For reproducing, Just create a vue 2 project and write a component in composition API. The setup would be called twice. Below is a simple vue for reproducing this issue:

<script setup lang="ts">
import {ref} from "@vue/composition-api";

const a = ref('aa')
const b = ref('bb')
console.log('call setup')
</script>

<template lang="pug">
span haha {{a}} {{b}}
</template>
spart4k commented 12 months ago

hey?

marcel-wtfoxtrot commented 10 months ago

Hey @xiaoxiangmoe ,

i just ran into the exact same issue using vue 2.7.14 and composition-api@1.7.2

here is a Reproduction Demo: https://codesandbox.io/s/confident-architecture-p6jm5p?file=/src/App.vue

Just have a look at the terminal. You'll find Setup being printed twice, mounted only once.

xiaoxiangmoe commented 10 months ago

Hi,@marcel-wtfoxtrot In vue 2.7, you needn't use composition-api, just use vue

wsxiao commented 8 months ago

Have you found the reason?