不器小窝 不器小窝
首页
随笔
  • GoLang
  • 前端

    • Vue
    • VuePress
  • 开发工具
  • 系统工具
读吧
  • ToDb (opens new window)
  • goKit (opens new window)
  • 友情链接
  • 免费信息
  • 时间线
  • 关于
GitHub (opens new window)

不器

知行合一
首页
随笔
  • GoLang
  • 前端

    • Vue
    • VuePress
  • 开发工具
  • 系统工具
读吧
  • ToDb (opens new window)
  • goKit (opens new window)
  • 友情链接
  • 免费信息
  • 时间线
  • 关于
GitHub (opens new window)
  • Js错误集合
  • Vue

    • Node.js安装与卸载
    • vue3基础
    • HTML使用vue3
      • 前言
      • 如何在单页中使用Vue3
      • 如何在单页中使用element ui
    • Vue3错误集合
    • Vue3经验
  • VuePress

  • CSS

  • naive-ui

  • Vue-Admin

  • 前端
  • Vue
不器
2022-09-21
目录

HTML使用vue3

# 前言

作为前端小白,Vue新手,怎么在HTML使用Vue3不知道,只好先记个笔记先。

# 如何在单页中使用Vue3

<!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</title>
    <style>
        [v-cloak] {
            display: none !important;
        }
    </style>
</head>
<body>
    <div id="app" v-cloak>
        <div>
            {{ state1 }}
        </div>
        <div>
            {{ message }}
        </div>
        <div>
            {{ num }}
        </div>
        <input type="text" name="" id="" placeholder="输入" v-model="input1"><br/>
        <input type="text" name="" id="" placeholder="输入" v-model="input2"><br/>
        <div>
            input1:{{ input1 }}
        </div>
        <div>
            input2:{{ input2 }}
        </div>
        <button @click="btn1">
            点我
        </button>
    </div>
    <!-- <script src="https://cdn.jsdelivr.net/npm/vue@3.0.11/dist/vue.global.js"></script> -->
    <script src="https://cdn.jsdelivr.net/npm/vue@3.0.11/dist/vue.global.prod.js"></script>
    <script>
        const { createApp, reactive, toRefs, ref, onMounted } = Vue;
        
        const app = createApp({
            setup() {
                var state1 = ref(123)
                var input2 = ref(123)
                const state = reactive({
                    message: 12,
                    num: 1,
                    input1: ''
                })
                onMounted(()=>{
                    console.log(2222)
                })
                const btn1 = () => {
                    console.log(state1)
                    console.log(input2)
                    console.log(state)
                    state1.value++
                    state.num++
                    
                }
                return {
                    ...toRefs(state),
                    state1,
                    input2,
                    btn1
                }
            }
        });
        app.mount("#app");
    </script>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

# 如何在单页中使用element ui

<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <script src="https://unpkg.com/vue@next"></script>
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
    <!-- import JavaScript -->
    <script src="https://unpkg.com/element-plus"></script>
    <title>Element Plus demo</title>
  </head>
  <body>
    <div id="app">
      <el-button>{{ message }}</el-button>
    </div>
    <script>
      const App = {
        data() {
          return {
            message: "Hello Element Plus",
          };
        },
      };
      const app = Vue.createApp(App);
      app.use(ElementPlus);
      app.mount("#app");
    </script>
  </body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#HTML#Vue3
更新时间: 2023/2/10 09:50:10
vue3基础
Vue3错误集合

← vue3基础 Vue3错误集合→

最近更新
01
Vue-pure-Admin基础
03-16
02
WebStorm工具使用手册
03-15
03
Windows
03-12
更多文章>
Theme by Vdoing | Copyright © 2022-2023 不器 | 小窝
sitemap icon by Icons8
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式