0
点赞
收藏
分享

微信扫一扫

vue3.0 组合式API 加加减减

通过cdn安装vue

setup()

createApp()

ref

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue3.0</title>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/3.0.11/vue.global.prod.js"></script>
</head>
<body>
<div id="app">
{{count}}
<div>
<button @click="handleAdd"></button>
<button @click="handleSub"></button>
</div>
</div>
<script>
let { createApp, ref } = Vue

createApp({
setup() {
let count = ref(0)

let handleAdd = () => {
count.value++
}

let handleSub = () => {
count.value--
}

return {
count,
handleAdd,
handleSub
}
}
}).mount('#app')
</script>
</body>
</html>

 


举报

相关推荐

0 条评论