HTML做网页,如何使用Vue3、Element-plus、Axios

2023-08-2017:14:23WEB前端开发Comments1,037 views字数 2084阅读模式

有时候我们写一个网页的时候,不想使用脚手架去搭建,因为太笨重,但又想使用vue3去实现,怎么办?文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/54122.html

下面就讲一讲如何实现!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/54122.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/54122.html

基本结构

<!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="https://unpkg.com/vue@3/dist/vue.global.js"></script>
...

使用vue3

具体vue3语法请看官网文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/54122.html

注意:setup语法糖,无法在html里面使用,请使用 setup() 函数 去处理!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/54122.html

<!-- 不支持 -->
<script setup>
   // doingsthing
</script>
HTML做网页,如何使用Vue3、Element-plus、Axios
错误写法示例

<!-- 正确用法 -->
...

<body>
<div id="app"></div>
</body>
...
<script>
 const { createApp } = Vue
 const APP = createApp({
    setup(){}
  })
 APP.mount('#app')
</script>

使用UI框架

这里以element-plus为例文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/54122.html

引入

...
<!-- 全局样式 -->
<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>
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/54122.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/gcs/54122.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定