36 lines
1.0 KiB
HTML
36 lines
1.0 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">
|
||
|
<div :style="{width:h, height:h, backgroundColor:bgc}"></div>
|
||
|
bgc:<input type="text" v-model="bgc">
|
||
|
</div>
|
||
|
</body>
|
||
|
<script>
|
||
|
// 将 Vue 对象中的createApp reactive 属性赋值给createApp reactive
|
||
|
const { createApp, reactive, ref } = Vue; // 解构赋值语法
|
||
|
// 创建一个 Vue 的应用程序
|
||
|
createApp({
|
||
|
// 组合式API 的 setup 用于设置响应式数据和方法
|
||
|
setup() {
|
||
|
const w = ref('500px');
|
||
|
const h = ref('500px');
|
||
|
const bgc = ref('red');
|
||
|
// 返回数据
|
||
|
return {
|
||
|
w, h, bgc
|
||
|
}
|
||
|
}
|
||
|
}).mount('#app') // 将 Vue 应用程序挂载到app元素上
|
||
|
</script>
|
||
|
|
||
|
</html>
|