基本结构
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>网页</title> </head> <body> </body> </html>
引入vue3
... <script src=" ...
使用vue3
具体vue3语法请看官网
注意:setup语法糖,无法在html里面使用,请使用 setup() 函数 去处理!
<!-- 不支持 --> <script setup> // doingsthing </script>
上面是错误写法
<!-- 正确用法 --> ... <body> <div id="app"></div> </body> ... <script> const { createApp } = Vue const APP = createApp({ setup(){} }) APP.mount('#app') </script>
使用UI框架
这里以element-plus为例
引入
... <!-- 全局样式 --> <link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css" /> <!-- UI --> <script src="https://unpkg.com/element-plus"></script> ...
基本使用
... <div id="app"> <el-input v-model="value" clearable /> </div> ... <script> const { createApp, ref } = Vue const APP = createApp({ setup(){ const value = ref(null) return { value } } }) APP.use(ElementPlus).mount('#app') </script>
交互
... <div id="app"> <el-button type="primary" @click="handle">提示</el-button> </div> ... <script> const { createApp, ref } = Vue const APP = createApp({ setup(){ const handle = () => { ElementPlus.ElMessage({ message: '点击!', type: 'success', }) } return { handle } } }) APP.use(ElementPlus).mount('#app') </script>
使用组件
... <script src="//unpkg.com/@element-plus/icons-vue"></script> ... <div id="app"> <el-button icon="edit" type="primary" @click="handle">提示</el-button> </div> ... <script> const { createApp, ref } = Vue const APP = createApp({ setup(){ const handle = () => { ElementPlus.ElMessage({ message: '点击!', type: 'success', }) } return { handle } } }) APP.component('edit',ElementPlusIconsVue.Edit) APP.use(ElementPlus).mount('#app') </script>
发送请求
... <script src="https://unpkg.com/axios/dist/axios.min.js"></script> ... <script> ... axios.post(url,options } ... </script>