使用Vue3可能踩的坑,本文只是使用了@vue/composition-api 而不是使用alpha版本的Vue3
v-on陷阱
<div @click="alert(1)"></div>
這句話是會報錯的 說找不到alert
爲什麼,Vue3 的模板只關注setup返回值,setup連this都沒有,何況window更是不可能直接暴露
還是乖乖地寫方法吧
修改後
<template>
<div @click="alert(1)"></div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive } from "@vue/composition-api";
export default defineComponent({
name: "Alert",
setup() {
return {
alert:(num)=> alert(num)
}
}
});
</script>
lastupdate: 20200227