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>

 

posted @ 2021-04-21 14:25  徐同保  阅读(79)  评论(0编辑  收藏  举报