
批改狀態(tài):合格
老師批語(yǔ):
npm init -y
webpack webpack-cli webpack-dev-server
src > index.js index.html
webpack.config.js
npm i html-webpack-plugin -D
const HtmlWebpackPlugin = require('html-webpack-plugin')
webpack
webpack serve
npm i axios -S
import axios from 'axios
axios get 與 post 的區(qū)別
headers: { 'content-type': 'application/x-www-form-urlencoded' }
axios 請(qǐng)求方式
axios.request(config)
axios.get(url[, config])
請(qǐng)求axios.delete(url[, config])
刪除axios.post(url[, data[, config]])
發(fā)送axios.head(url[, config])
axios.put(url[, data[, config]])
axios.patch(url[, data[, config]])
axios 處理并發(fā)請(qǐng)求
跟 promise 一樣 使用 axios.all()
axios 攔截器
請(qǐng)求攔截器
axios.interceptors.request.use((config) => {
console.log("########");
});
響應(yīng)攔截器
axios.interceptors.response.use()((config) => {
console.log("########");
});
axios 全局配置
//主地址
axios.defaults.baseURL = "http://127.0.0.1";
//延時(shí)時(shí)間
axios.defaults.timeout = 5000;
//post請(qǐng)求頭
axios.defaults.headers.post["content-type"] = "application/x-www-form-urlencoded";
axios 實(shí)例封裝
由于現(xiàn)在大部分都是多服務(wù)器,且不同服務(wù)器超時(shí)時(shí)長(zhǎng)不一樣,沒(méi)法將后臺(tái)所有域名都加到 url 中,可以再封裝一個(gè) axios 來(lái)執(zhí)行
const instance = axios.create({
url: "http://localhost.com",
timeout: 3000,
method: "post",
});
instance.get("http://localhost.com");
npm i @vue/cli -g
vue -V
vue create '項(xiàng)目名'
npm run serve
創(chuàng)建內(nèi)容及注意事項(xiàng)
<template>
<!-- div外層標(biāo)簽必須有,標(biāo)簽內(nèi)內(nèi)容都填在這里面 -->
<div>
{{ msg }}
<hr />
{{ info() }}
</div>
</template>
<script>
export default {
name: "App2",
data() {
return {
msg: "this is a test",
name: "admin",
};
},
methods: {
info() {
return `my name is ${this.name}`;
},
},
};
</script>
<style scoped></style>
-js 主入口文件
import { createApp } from "vue";
// 這里導(dǎo)出的是匿名的 就隨意起名就是了 不要用解構(gòu)賦值 沒(méi)值啊,用了會(huì)有問(wèn)題
import App2 from "./App2.vue";
createApp(App2).mount("#app");
<!DOCTYPE html>
<html lang="zh-CN">
<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>Document</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)