chore: 编写基础示例
parent
b6698ca22d
commit
17022d2c98
|
@ -1 +1,4 @@
|
||||||
/dist
|
dist/
|
||||||
|
|
||||||
|
example/dist/
|
||||||
|
example/config/**.js
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
|
example/dist/
|
||||||
|
example/config/**.js
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
dist/
|
|
||||||
config/**.js
|
|
|
@ -19,7 +19,7 @@ const config = {
|
||||||
},
|
},
|
||||||
sourceRoot: 'src',
|
sourceRoot: 'src',
|
||||||
outputRoot: 'dist',
|
outputRoot: 'dist',
|
||||||
plugins: [],
|
plugins: ['@tarojs/plugin-html'],
|
||||||
defineConstants: {},
|
defineConstants: {},
|
||||||
copy: {
|
copy: {
|
||||||
patterns: [],
|
patterns: [],
|
||||||
|
|
|
@ -36,11 +36,13 @@
|
||||||
"@tarojs/runtime": "3.6.6",
|
"@tarojs/runtime": "3.6.6",
|
||||||
"@tarojs/shared": "3.6.6",
|
"@tarojs/shared": "3.6.6",
|
||||||
"@tarojs/taro": "3.6.6",
|
"@tarojs/taro": "3.6.6",
|
||||||
|
"axios-miniprogram": "workspace:*",
|
||||||
"vue": "^3.0.0"
|
"vue": "^3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.8.0",
|
"@babel/core": "^7.8.0",
|
||||||
"@tarojs/cli": "3.6.6",
|
"@tarojs/cli": "3.6.6",
|
||||||
|
"@tarojs/plugin-html": "^3.6.6",
|
||||||
"@tarojs/webpack5-runner": "3.6.6",
|
"@tarojs/webpack5-runner": "3.6.6",
|
||||||
"@types/webpack-env": "^1.13.6",
|
"@types/webpack-env": "^1.13.6",
|
||||||
"@vue/babel-plugin-jsx": "^1.0.6",
|
"@vue/babel-plugin-jsx": "^1.0.6",
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"projectname": "axios-miniprogram",
|
"projectname": "axios-miniprogram",
|
||||||
"appid": "wx48e277051b32f95b",
|
"appid": "wx48e277051b32f95b",
|
||||||
"setting": {
|
"setting": {
|
||||||
"urlCheck": true,
|
"urlCheck": false,
|
||||||
"es6": false,
|
"es6": false,
|
||||||
"enhance": false,
|
"enhance": false,
|
||||||
"compileHotReLoad": false,
|
"compileHotReLoad": false,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { createApp } from 'vue';
|
import { createApp } from 'vue';
|
||||||
import './app.css';
|
|
||||||
|
|
||||||
export default createApp({});
|
export default createApp({});
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
export default definePageConfig({
|
|
||||||
navigationBarTitleText: '首页',
|
|
||||||
});
|
|
|
@ -1,16 +1,126 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import axios from 'axios-miniprogram';
|
||||||
|
|
||||||
|
const config = ref<string>('');
|
||||||
|
const response = ref<string>('');
|
||||||
|
const error = ref<string>('');
|
||||||
|
|
||||||
|
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com';
|
||||||
|
axios.defaults.errorHandler = (err) => {
|
||||||
|
error.value = `<pre>${JSON.stringify(err, null, 4)}</pre>`;
|
||||||
|
return Promise.reject(err);
|
||||||
|
};
|
||||||
|
axios.use(async (ctx, next) => {
|
||||||
|
config.value = `<pre>${JSON.stringify(ctx.req, null, 4)}</pre>`;
|
||||||
|
await next();
|
||||||
|
response.value = `<pre>${JSON.stringify(ctx.res, null, 4)}</pre>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
function getRequest() {
|
||||||
|
axios.get('/users/:id', {
|
||||||
|
id: 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function postRequest() {
|
||||||
|
axios.post('/users', {
|
||||||
|
name: 'Leanne Graham',
|
||||||
|
username: 'Bret',
|
||||||
|
email: 'Sincere@april.biz',
|
||||||
|
address: {
|
||||||
|
street: 'Kulas Light',
|
||||||
|
suite: 'Apt. 556',
|
||||||
|
city: 'Gwenborough',
|
||||||
|
zipcode: '92998-3874',
|
||||||
|
geo: {
|
||||||
|
lat: '-37.3159',
|
||||||
|
lng: '81.1496',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
phone: '1-770-736-8031 x56442',
|
||||||
|
website: 'hildegard.org',
|
||||||
|
company: {
|
||||||
|
name: 'Romaguera-Crona',
|
||||||
|
catchPhrase: 'Multi-layered client-server neural-net',
|
||||||
|
bs: 'harness real-time e-markets',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function putRequest() {
|
||||||
|
axios.put('/users/:id', {
|
||||||
|
id: 1,
|
||||||
|
name: 'Leanne Graham',
|
||||||
|
username: 'Bret',
|
||||||
|
email: 'Sincere@april.biz',
|
||||||
|
address: {
|
||||||
|
street: 'Kulas Light',
|
||||||
|
suite: 'Apt. 556',
|
||||||
|
city: 'Gwenborough',
|
||||||
|
zipcode: '92998-3874',
|
||||||
|
geo: {
|
||||||
|
lat: '-37.3159',
|
||||||
|
lng: '81.1496',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
phone: '1-770-736-8031 x56442',
|
||||||
|
website: 'hildegard.org',
|
||||||
|
company: {
|
||||||
|
name: 'Romaguera-Crona',
|
||||||
|
catchPhrase: 'Multi-layered client-server neural-net',
|
||||||
|
bs: 'harness real-time e-markets',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteRequest() {
|
||||||
|
axios.delete('/users/:id', {
|
||||||
|
id: 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
getRequest,
|
||||||
|
postRequest,
|
||||||
|
putRequest,
|
||||||
|
deleteRequest,
|
||||||
|
config,
|
||||||
|
response,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view class="index">
|
<view>
|
||||||
<text>{{ msg }}</text>
|
<button class="button" type="primary" @click="getRequest">GET 请求</button>
|
||||||
|
<button class="button" type="primary" @click="postRequest">
|
||||||
|
POST 请求
|
||||||
|
</button>
|
||||||
|
<button class="button" type="primary" @click="putRequest">PUT 请求</button>
|
||||||
|
<button class="button" type="primary" @click="deleteRequest">
|
||||||
|
DELETE 请求
|
||||||
|
</button>
|
||||||
|
|
||||||
|
config:
|
||||||
|
<view class="code" v-html="config"></view>
|
||||||
|
|
||||||
|
response:
|
||||||
|
<view class="code" v-html="response"></view>
|
||||||
|
|
||||||
|
error:
|
||||||
|
<view class="code" v-html="error"></view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<style>
|
||||||
import { ref } from 'vue'
|
.button {
|
||||||
import './index.css'
|
margin: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
const msg = ref('Hello world')
|
.code {
|
||||||
|
padding: 20px;
|
||||||
defineExpose({
|
overflow-x: scroll;
|
||||||
msg,
|
white-space: pre;
|
||||||
})
|
}
|
||||||
</script>
|
</style>
|
||||||
|
|
|
@ -87,6 +87,7 @@ importers:
|
||||||
'@tarojs/components': 3.6.6
|
'@tarojs/components': 3.6.6
|
||||||
'@tarojs/helper': 3.6.6
|
'@tarojs/helper': 3.6.6
|
||||||
'@tarojs/plugin-framework-vue3': 3.6.6
|
'@tarojs/plugin-framework-vue3': 3.6.6
|
||||||
|
'@tarojs/plugin-html': ^3.6.6
|
||||||
'@tarojs/plugin-platform-alipay': 3.6.6
|
'@tarojs/plugin-platform-alipay': 3.6.6
|
||||||
'@tarojs/plugin-platform-h5': 3.6.6
|
'@tarojs/plugin-platform-h5': 3.6.6
|
||||||
'@tarojs/plugin-platform-jd': 3.6.6
|
'@tarojs/plugin-platform-jd': 3.6.6
|
||||||
|
@ -101,6 +102,7 @@ importers:
|
||||||
'@types/webpack-env': ^1.13.6
|
'@types/webpack-env': ^1.13.6
|
||||||
'@vue/babel-plugin-jsx': ^1.0.6
|
'@vue/babel-plugin-jsx': ^1.0.6
|
||||||
'@vue/compiler-sfc': ^3.0.0
|
'@vue/compiler-sfc': ^3.0.0
|
||||||
|
axios-miniprogram: workspace:*
|
||||||
babel-preset-taro: 3.6.6
|
babel-preset-taro: 3.6.6
|
||||||
css-loader: 3.4.2
|
css-loader: 3.4.2
|
||||||
eslint-plugin-vue: ^8.0.0
|
eslint-plugin-vue: ^8.0.0
|
||||||
|
@ -126,10 +128,12 @@ importers:
|
||||||
'@tarojs/runtime': 3.6.6
|
'@tarojs/runtime': 3.6.6
|
||||||
'@tarojs/shared': 3.6.6
|
'@tarojs/shared': 3.6.6
|
||||||
'@tarojs/taro': 3.6.6_vue@3.2.47
|
'@tarojs/taro': 3.6.6_vue@3.2.47
|
||||||
|
axios-miniprogram: link:..
|
||||||
vue: 3.2.47
|
vue: 3.2.47
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@babel/core': 7.21.8
|
'@babel/core': 7.21.8
|
||||||
'@tarojs/cli': 3.6.6_vue@3.2.47
|
'@tarojs/cli': 3.6.6_vue@3.2.47
|
||||||
|
'@tarojs/plugin-html': 3.6.6_vue@3.2.47
|
||||||
'@tarojs/webpack5-runner': 3.6.6_ccyaxh63edqyfdgniosjbfvodu
|
'@tarojs/webpack5-runner': 3.6.6_ccyaxh63edqyfdgniosjbfvodu
|
||||||
'@types/webpack-env': 1.18.0
|
'@types/webpack-env': 1.18.0
|
||||||
'@vue/babel-plugin-jsx': 1.1.1_@babel+core@7.21.8
|
'@vue/babel-plugin-jsx': 1.1.1_@babel+core@7.21.8
|
||||||
|
@ -2592,6 +2596,21 @@ packages:
|
||||||
- supports-color
|
- supports-color
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/@tarojs/plugin-html/3.6.6_vue@3.2.47:
|
||||||
|
resolution: {integrity: sha512-mkdsum+nZbwIYxuBNYRABz664wRQogYqdAjKcnjio8J4NbtM7sBhwlugNjs6MaeA0GM0Jle6Y+biw6RkGrHklA==}
|
||||||
|
dependencies:
|
||||||
|
'@babel/parser': 7.21.8
|
||||||
|
'@tarojs/runtime': 3.6.6
|
||||||
|
'@tarojs/service': 3.6.6_vue@3.2.47
|
||||||
|
'@tarojs/shared': 3.6.6
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- '@types/react'
|
||||||
|
- '@types/webpack'
|
||||||
|
- '@types/webpack-dev-server'
|
||||||
|
- supports-color
|
||||||
|
- vue
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@tarojs/plugin-platform-alipay/3.6.6_vue@3.2.47:
|
/@tarojs/plugin-platform-alipay/3.6.6_vue@3.2.47:
|
||||||
resolution: {integrity: sha512-65SFA8Vmlwf5ZflI+jXN3W2nrh2NYM3GRAjOcZDIPE+6Je33Bi/7jNaTn3t+YwJlcVjY6djp3/dmC+xwc7skfA==}
|
resolution: {integrity: sha512-65SFA8Vmlwf5ZflI+jXN3W2nrh2NYM3GRAjOcZDIPE+6Je33Bi/7jNaTn3t+YwJlcVjY6djp3/dmC+xwc7skfA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in New Issue