chore: 编写基础示例
parent
b6698ca22d
commit
17022d2c98
|
@ -1 +1,4 @@
|
|||
/dist
|
||||
dist/
|
||||
|
||||
example/dist/
|
||||
example/config/**.js
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
CHANGELOG.md
|
||||
dist/
|
||||
|
||||
example/dist/
|
||||
example/config/**.js
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
dist/
|
||||
config/**.js
|
|
@ -19,7 +19,7 @@ const config = {
|
|||
},
|
||||
sourceRoot: 'src',
|
||||
outputRoot: 'dist',
|
||||
plugins: [],
|
||||
plugins: ['@tarojs/plugin-html'],
|
||||
defineConstants: {},
|
||||
copy: {
|
||||
patterns: [],
|
||||
|
|
|
@ -36,11 +36,13 @@
|
|||
"@tarojs/runtime": "3.6.6",
|
||||
"@tarojs/shared": "3.6.6",
|
||||
"@tarojs/taro": "3.6.6",
|
||||
"axios-miniprogram": "workspace:*",
|
||||
"vue": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.8.0",
|
||||
"@tarojs/cli": "3.6.6",
|
||||
"@tarojs/plugin-html": "^3.6.6",
|
||||
"@tarojs/webpack5-runner": "3.6.6",
|
||||
"@types/webpack-env": "^1.13.6",
|
||||
"@vue/babel-plugin-jsx": "^1.0.6",
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"projectname": "axios-miniprogram",
|
||||
"appid": "wx48e277051b32f95b",
|
||||
"setting": {
|
||||
"urlCheck": true,
|
||||
"urlCheck": false,
|
||||
"es6": false,
|
||||
"enhance": false,
|
||||
"compileHotReLoad": false,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { createApp } from 'vue';
|
||||
import './app.css';
|
||||
|
||||
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>
|
||||
<view class="index">
|
||||
<text>{{ msg }}</text>
|
||||
<view>
|
||||
<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>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue'
|
||||
import './index.css'
|
||||
<style>
|
||||
.button {
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
const msg = ref('Hello world')
|
||||
|
||||
defineExpose({
|
||||
msg,
|
||||
})
|
||||
</script>
|
||||
.code {
|
||||
padding: 20px;
|
||||
overflow-x: scroll;
|
||||
white-space: pre;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -87,6 +87,7 @@ importers:
|
|||
'@tarojs/components': 3.6.6
|
||||
'@tarojs/helper': 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-h5': 3.6.6
|
||||
'@tarojs/plugin-platform-jd': 3.6.6
|
||||
|
@ -101,6 +102,7 @@ importers:
|
|||
'@types/webpack-env': ^1.13.6
|
||||
'@vue/babel-plugin-jsx': ^1.0.6
|
||||
'@vue/compiler-sfc': ^3.0.0
|
||||
axios-miniprogram: workspace:*
|
||||
babel-preset-taro: 3.6.6
|
||||
css-loader: 3.4.2
|
||||
eslint-plugin-vue: ^8.0.0
|
||||
|
@ -126,10 +128,12 @@ importers:
|
|||
'@tarojs/runtime': 3.6.6
|
||||
'@tarojs/shared': 3.6.6
|
||||
'@tarojs/taro': 3.6.6_vue@3.2.47
|
||||
axios-miniprogram: link:..
|
||||
vue: 3.2.47
|
||||
devDependencies:
|
||||
'@babel/core': 7.21.8
|
||||
'@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
|
||||
'@types/webpack-env': 1.18.0
|
||||
'@vue/babel-plugin-jsx': 1.1.1_@babel+core@7.21.8
|
||||
|
@ -2592,6 +2596,21 @@ packages:
|
|||
- supports-color
|
||||
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:
|
||||
resolution: {integrity: sha512-65SFA8Vmlwf5ZflI+jXN3W2nrh2NYM3GRAjOcZDIPE+6Je33Bi/7jNaTn3t+YwJlcVjY6djp3/dmC+xwc7skfA==}
|
||||
dependencies:
|
||||
|
|
Loading…
Reference in New Issue