当前位置: 首页 > news >正文

JavaWeb:vueaxios

一、简介

什么是vue?

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

快速入门

在这里插入图片描述

 <!-- 3.准备视图元素 --><div id="app"><!-- 6.数据渲染 --><h1>{{ msg }}</h1></div><script type="module">// 1.引入vueimport { createApp, ref } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'// 2.创建Vue实例const app = createApp({// 4.定义数据模型data() {return {msg: 'Hello Vue!'}}}).mount('#app') //5.挂载视图</script>

二、基础-常用指令

在这里插入图片描述
在这里插入图片描述

v-for

在这里插入图片描述

  <div id="app"><!-- <p v-for="name in names">{{name}}</p> --><p v-for="(name, index) in names">{{index + 1}} : {{name}}</p></div><script type="module">import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'createApp({data(){return {names: ['张无忌', '张三丰', '韦一笑', '殷天正']}}}).mount('#app')</script>

v-bind

在这里插入图片描述

  <div id="app"><a v-bind:href="url">链接1</a><br><br><a :href="url">链接2</a></div><script type="module">import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'createApp({data(){return {url: "https://www.4399.com"}}}).mount('#app')</script>

v-if&v-show

在这里插入图片描述

      <tr v-for="(user, index) in userList"><td>{{index+1}}</td><td>{{user.name}}</td><td> <img :src="user.image"> </td><td><span v-if="user.gender==1"></span><span v-else-if></span><span v-else></span></td><td><span v-show="user.job==1">讲师</span><span v-show="user.job==2">班主任</span><span v-show="user.job!=1 && user.job!=2">其他</span></td>

在这里插入图片描述

v-model-双向数据绑定

在这里插入图片描述

 <div id="app"><input type="text" v-model="name"> {{name}}</div><script type="module">import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'createApp({data(){return {name: 'Tom'}}}).mount('#app')</script>

在这里插入图片描述

v-on

在这里插入图片描述

 <div id="app"><input type="button" value="点我一下试试" v-on:click="console.log('试试就试试1')"><input type="button" value="再点我一下试试" v-on:click="handle"><input type="button" value="再点我一下试试3" @click="handle"></div><script type="module">import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'createApp({// 数据模型data(){return {name: 'Vue'}},// 定义函数methods: {handle(){console.log("试试就试试3");}},}).mount('#app')</script>

案例:获取用户输入条件

效果图上面列表

<!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-案例1</title><style>table,th,td {border: 1px solid #000;border-collapse: collapse;line-height: 50px;text-align: center;}#center,table {width: 60%;margin: auto;}#center {margin-bottom: 20px;}img {width: 50px;}input,select {width: 17%;padding: 10px;margin-right: 30px;border: 1px solid #ccc;border-radius: 4px;}.btn {background-color: #ccc;}</style>
</head><body><div id="app"><div id="center">姓名: <input type="text" name="name" v-model="name">性别:<select name="gender" v-model="gender"><option value="1"></option><option value="2"></option></select>职位:<select name="job" v-model="job"><option value="1">讲师</option><option value="2">班主任</option><option value="3">其他</option></select><input class="btn" type="button" value="查询" @click="query"></div><!-- {{name}}, {{gender}}, {{job}} --><table><tr><th>序号</th><th>姓名</th><th>头像</th><th>性别</th><th>职位</th><th>入职时间</th><th>更新时间</th></tr><tr v-for="(user, index) in userList"><td>{{index+1}}</td><td>{{user.name}}</td><td> <img :src="user.image"> </td><td><span v-if="user.gender==1"></span><span v-else-if></span><span v-else></span></td><td><span v-show="user.job==1">讲师</span><span v-show="user.job==2">班主任</span><span v-show="user.job!=1 && user.job!=2">其他</span></td><td>{{user.entrydate}}</td><td>{{user.updatetime}}</td></tr></table></div><script type="module">import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'createApp({data() {return {name: '',gender: '',job: '',userList: [{"id": 1,"name": "谢逊","image": "https://web-framework.oss-cn-hangzhou.aliyuncs.com/2023/1.jpg","gender": 1,"job": 1,"entrydate": "2023-06-09","updatetime": "2023-07-01 00:00:00"},{"id": 2,"name": "韦一笑","image": "https://web-framework.oss-cn-hangzhou.aliyuncs.com/2023/2.jpg","gender": 1,"job": 1,"entrydate": "2023-06-09","updatetime": "2023-07-01 00:00:00"},{"id": 3,"name": "黛绮丝","image": "https://web-framework.oss-cn-hangzhou.aliyuncs.com/2023/3.jpg","gender": 2,"job": 2,"entrydate": "2023-06-09","updatetime": "2023-07-01 00:00:00"},{"id": 4,"name": "殷天正","image": "https://web-framework.oss-cn-hangzhou.aliyuncs.com/2023/4.jpg","gender": 1,"job": 3,"entrydate": "2023-06-09","updatetime": "2023-07-01 00:00:00"}]}},methods: {query() {console.log(this.name + " " + this.gender + " " + this.job);}}}).mount("#app");</script>
</body></html>

三、Ajax

什么是ajax?

在这里插入图片描述

    <input id="btn1" type="button" value="获取数据"><div id="div1"></div><script>document.querySelector('#btn1').addEventListener('click', ()=> {//1. 创建XMLHttpRequest var xmlHttpRequest  = new XMLHttpRequest();//2. 发送异步请求xmlHttpRequest.open('GET', 'https://mock.apifox.cn/m1/3128855-0-default/emp/list');xmlHttpRequest.send();//发送请求//3. 获取服务响应数据xmlHttpRequest.onreadystatechange = function(){if(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200){document.getElementById('div1').innerHTML = xmlHttpRequest.responseText;}}})</script>
同步和异步

在这里插入图片描述

原生ajax

在这里插入图片描述

小结

在这里插入图片描述

axios使用

在这里插入图片描述

   <input type="button" value="获取数据GET" id="btnGet"><input type="button" value="删除数据POST" id="btnPost"><!-- 1.引入js文件 --><script src="https://unpkg.com/axios/dist/axios.min.js"></script><!-- <script src="../js/axios.js"></script> --><script>document.querySelector("#btnGet").addEventListener('click', function(){// 调用axios发送get请求 https://mock.apifox.cn/m1/3083103-0-default/emps/listaxios({method: 'GET',url: 'https://mock.apifox.cn/m1/3083103-0-default/emps/list'}).then((result)=>{     //成功回调函数console.log(result.data);    console.log(result.data.data);    }).catch((err)=>{       //失败回调函数alert(err);})})document.querySelector("#btnPost").addEventListener('click', function(){// 调用axios发送post请求 https://mock.apifox.cn/m1/3083103-0-default/emps/updateaxios({method: 'POST',url: 'https://mock.apifox.cn/m1/3083103-0-default/emps/update',data: 'id=1'    //封装请求参数}).then((result)=>{     //成功回调函数console.log(result.data);    }).catch((err)=>{       //失败回调函数alert(err);})})</script>
axios请求方式别名

在这里插入图片描述
在这里插入图片描述

axios案例

在这里插入图片描述

<!-- 1.引入js文件 --><script src="https://unpkg.com/axios/dist/axios.min.js"></script><script type="module">import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'createApp({data() {return {name: '',gender: '',job: '',userList: []}},methods: {// 输出搜索框中数据query() {console.log(this.name + " " + this.gender + " " + this.job);// https://web-server.itheima.net/emps/listaxios.get('https://web-server.itheima.net/emps/list', {params: {name: this.name,gender: this.gender,job: this.job}}).then((result)=>{     //成功回调函数console.log(result.data);    this.userList = result.data.data;    })}}}).mount("#app");</script>

问题:没有自动加载——生命周期

四、生命周期

生命周期

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

    <div id="app"><p v-for="(name, index) in names">{{index + 1}} : {{name}}</p></div><script type="module">import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'createApp({// 数据模型data(){return {names: ['张无忌', '张三丰', '韦一笑', '殷天正']}},// 定义函数methods: {},// 钩子函数(生命周期方法)created() {console.log("对象创建完成....");},mounted() {console.log("页面挂载完成...");},}).mount('#app')</script>
案例改造
      // 钩子函数(生命周期方法)mounted() {// 页面加载完成即可查询this.query();},
总结

在这里插入图片描述

五、案例

省市县

在这里插入图片描述
在这里插入图片描述

async&await

在这里插入图片描述

http://www.xdnf.cn/news/200809.html

相关文章:

  • MetaEditor - 自动交易和技术指标编辑器
  • 知识体系_用户研究_用户体验度量模型
  • Python3:Jupyterlab 安装和配置
  • Java并发探索--上篇
  • SD04_CurSor提示词
  • 计算字符串的编辑距离和单向链表中倒数第k个结点
  • 普推知产:商标驳回复审下初步审定公告了!
  • 【C++】Googletest应用
  • python+selenium的web自动化之元素的常用操作
  • 人物5_My roommate
  • 【java】接口
  • linux跟踪调试进程异常的方法
  • Verilog基础:生成块结构(Generate)
  • 将python程序创建成可以在扣子中运行的插件
  • CH592/CH582 触摸按键应用开发实例讲解
  • 面向城市治理的AI集群空域融合模型
  • 数据仓库建模:方法、技巧与实践
  • 罗马数字转整数(简单)
  • pidstat 使用教程:功能介绍及实战示例
  • 用jmeter压测接口,并生成压测报告
  • 工业通讯现场中关于EtherCAT转TCPIP网关的现场应用
  • 初识c++
  • Miniconda Windows10版本下载和安装
  • 工业园区工厂企业数字IP广播应急呼叫对讲系统:数字IP广播极大提升工厂企业管理效率与应急响应效能
  • JAVA实现将富文本内容插入已有word文档并下载(dock4j+jsoup)
  • 【OSG学习笔记】Day 12: 回调机制——动态更新场景
  • Vue 3 vuedraggable 例子
  • AI网文热门题材生成用什么?小说创作工具来帮忙
  • C++中的智能指针
  • 双向流-固计算前处理和耦合设置