38 lines
1.1 KiB
HTML
38 lines
1.1 KiB
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>
|
||
|
<!-- 1. 导入vue.js的脚本文件 -->
|
||
|
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
<div id="app">
|
||
|
<p>count的值为: {{count}}</p>
|
||
|
<button v-on:click="addCount"> +1 </button>
|
||
|
<button @click="count+=1"> +1 </button>
|
||
|
</div>
|
||
|
</body>
|
||
|
<script>
|
||
|
// 将 Vue 对象中的createApp reactive 属性赋值给createApp reactive
|
||
|
const { createApp, reactive, ref } = Vue; // 解构赋值语法
|
||
|
// 创建一个 Vue 的应用程序
|
||
|
createApp({
|
||
|
// 组合式API 的 setup 用于设置响应式数据和方法
|
||
|
setup() {
|
||
|
const count = ref(0);
|
||
|
const addCount = () => {
|
||
|
count.value++;
|
||
|
}
|
||
|
// 返回数据
|
||
|
return {
|
||
|
count, addCount
|
||
|
}
|
||
|
}
|
||
|
}).mount('#app') // 将 Vue 应用程序挂载到app元素上
|
||
|
</script>
|
||
|
|
||
|
</html>
|