Vue3-响应式基础:单文件和组合式文件

 单文件:html

<!DOCTYPE html>
<html>
<head>
    <title>响应式基础</title>
</head>
<body>
    <div id="app" >
        <!-- dynamic parameter:同样在指令参数上也可以使用一个 JavaScript 表达式,需要包含在一对方括号内: -->
    </div>
    <!-- 引入Vue.js -->
    <script type="module">
      import { createApp,ref } from "https://unpkg.com/vue@3/dist/vue.esm-browser.js"
      const count = ref(0)

      console.log(count)   // { value: 0 }
      console.log(count.value)  // 0


      createApp({
        data(){
          return {
          }
        }
      }).mount('#app')
    </script>

    
</body>
</html>

组合文件

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
    <script type="module">
        import {createApp, ref} from "https://unpkg.com/vue@3/dist/vue.esm-browser.js"
        import count from './reactive.js'

        createApp(count).mount('#app')
    </script>
</body>
</html>

reactive.js

import { ref } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'

export default {
  // `setup` 是一个特殊的钩子,专门用于组合式 API。
  setup() {
    const count = ref(0)

    // 将 ref 暴露给模板
    return {
      count
    }
  }
}

​​​​​​​

相关推荐

  1. vue3基础文件组件介绍

    2024-03-17 01:20:02       64 阅读
  2. vue2响应vue3响应

    2024-03-17 01:20:02       26 阅读
  3. Vue3响应基础——ref()reactive()

    2024-03-17 01:20:02       36 阅读
  4. vue3-响应基础之ref

    2024-03-17 01:20:02       58 阅读
  5. vue响应基础

    2024-03-17 01:20:02       37 阅读
  6. VUE3-响应

    2024-03-17 01:20:02       55 阅读
  7. Vue3---基础4(响应数据) Vue2

    2024-03-17 01:20:02       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-17 01:20:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-17 01:20:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-17 01:20:02       82 阅读
  4. Python语言-面向对象

    2024-03-17 01:20:02       91 阅读

热门阅读

  1. 一文解读ISO26262安全标准:术语(二)

    2024-03-17 01:20:02       41 阅读
  2. linux系统kubernetes概念

    2024-03-17 01:20:02       41 阅读
  3. MySQL建表以及excel内容导入

    2024-03-17 01:20:02       37 阅读
  4. 什么是面向对象

    2024-03-17 01:20:02       37 阅读