提交 690fe8cd 编写于 作者: W wuyb

123

上级 4c83b65f
{
"env": "dev",
"target": "http://localhost:3000"
}
\ No newline at end of file
// proxy.js
const fs = require('fs')
const path = require('path')
const encoding = 'utf-8'
/**
* 获取配置文件内容 getContent('proxy-config.json')
* @param filename env.json
* @returns {string}
*/
const getContent = filename => {
const dir = path.resolve(process.cwd(), 'environments')
const target = fs.readFileSync(path.resolve(dir, filename), { encoding })
console.log('target',target);
return target
}
const jsonParse = obj => {
return Function('"use strict";return (' + obj + ')')()
}
/**
* 获取配置选项 getConfig()
* @returns {{}|*}
*/
const getConfig = () => {
try {
console.log('getContent(\'proxy-config.json\')',getContent('proxy-config.json'));
return jsonParse(getContent('proxy-config.json'))
} catch (e) {
return {}
}
}
module.exports = {
proxy: {
// 接口匹配规则自行修改
// ['/my-api']: {
// target: 'that must have a empty placeholder', // 这里必须要有字符串来进行占位
// changeOrigin: true,
// router: () => (getConfig() || {}).target || ''
// },
'/ReportApi': {
target: 'http://192.168.145.101:13000',
// target: 'http://localhost:3000',
changeOrigin: true,//允许跨域
rewrite: (path) => path.replace(/^\/api/, ''),
router: () => (getConfig() || {}).target || ''
},
'/api': {
target: 'localhost',
changeOrigin: true,//允许跨域
rewrite: (path) => path.replace(/^\/api/, ''),
router: () => (getConfig() || {}).target || ''
},
}
}
...@@ -33,7 +33,7 @@ module.exports = [ ...@@ -33,7 +33,7 @@ module.exports = [
type: 'post', type: 'post',
response: config => { response: config => {
const {username} = config.body const {username} = config.body
console.log('mock', config.body); // console.log('mock', config.body);
const token = tokens[username] const token = tokens[username]
console.log(token); console.log(token);
if (!token) { if (!token) {
...@@ -54,7 +54,7 @@ module.exports = [ ...@@ -54,7 +54,7 @@ module.exports = [
url: '/api/user/info', url: '/api/user/info',
type: 'get', type: 'get',
response: config => { response: config => {
console.log('/api/user/info - config',config); // console.log('/api/user/info - config',config);
const {token} = config.headers const {token} = config.headers
const info = users[token] const info = users[token]
......
此差异已折叠。
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"mockjs": "^1.1.0", "mockjs": "^1.1.0",
"vite": "^2.9.0", "vite": "^2.9.0",
"vite-plugin-mock": "^2.9.6" "vite-plugin-mock": "^2.9.6",
"vue-virtual-scroller": "^1.1.2"
} }
} }
...@@ -6,4 +6,18 @@ export function tabelAll(data) { ...@@ -6,4 +6,18 @@ export function tabelAll(data) {
method: 'get', method: 'get',
data data
}) })
}
export function myApi() {
return request({
url: '/api/my-api',
method: 'get'
})
}
export function getLaoWu666() {
return request({
url: '/ReportApi/impCostEnergy/getLaoWu666',
method: 'get'
})
} }
\ No newline at end of file
...@@ -138,6 +138,15 @@ export default [ ...@@ -138,6 +138,15 @@ export default [
}, },
component: '/views/MyUI/UI.vue', component: '/views/MyUI/UI.vue',
}, },
{
path: '/dynamicAgent',
name: 'dynamicAgent',
title: '动态代理',
meta: {
title: '动态代理',
},
component: '/views/tool/dynamicAgent.vue',
},
] ]
}, },
{ {
......
<template>
<div id="responsiveApp"></div>
</template>
<script>
export default {
name: "responsive",
setup() {
return {}
}
}
</script>
<style scoped>
</style>
\ No newline at end of file
<template> <template>
<a-tabs v-model:activeKey="activeKey" type="card"> <a-tabs v-model:activeKey="activeKey" type="card">
<a-tab-pane key="1" tab="jsx的使用和插槽传参"> <a-tab-pane key="1" tab="jsx的使用和插槽传参">
<jsx></jsx> <jsx></jsx>
</a-tab-pane>
<a-tab-pane key="2" tab="vue中的attrs" force-render>
<a-tabs tab-position="left">
<a-tab-pane key="1" tab="Tab 1">
<attrsVue3></attrsVue3>
</a-tab-pane> </a-tab-pane>
<a-tab-pane key="2" tab="$attrs"> <a-tab-pane key="2" tab="vue中的attrs" force-render>
<attrs/> <a-tabs tab-position="left">
<a-tab-pane key="1" tab="Tab 1">
<attrsVue3></attrsVue3>
</a-tab-pane>
<a-tab-pane key="2" tab="$attrs">
<attrs/>
</a-tab-pane>
</a-tabs>
</a-tab-pane> </a-tab-pane>
</a-tabs> <a-tab-pane key="3" tab="compositionApi">
</a-tab-pane> <compositionAPI/>
<a-tab-pane key="3" tab="compositionApi"> </a-tab-pane>
<compositionAPI/> <a-tab-pane key="4" tab="插槽">
</a-tab-pane> <slots></slots>
<a-tab-pane key="4" tab="插槽">
<slots></slots>
<FancyButton>
2444
<span style="color:red">Click me!</span>
<template #header="{count}">
<div>
作用域插槽 -
<p>{{ count }}</p>
</div>
<tree></tree>
</template>
</FancyButton>
</a-tab-pane>
</a-tabs> <FancyButton>
2444
<span style="color:red">Click me!</span>
<template #header="{count}">
<div>
作用域插槽 -
<p>{{ count }}</p>
</div>
<tree></tree>
</template>
</FancyButton>
</a-tab-pane>
<a-tab-pane key="5" tab="Vue3响应式系统-源码">
<responsive></responsive>
</a-tab-pane>
</a-tabs>
</template> </template>
<script> <script>
import {ref} from 'vue' import {ref} from 'vue'
// jsx // jsx
import jsx from '../components/jsx/index.vue' import jsx from '../components/jsx/index.vue'
import attrsVue3 from "../components/attrs/vue3-attrs/index.vue"; import attrsVue3 from "../components/attrs/vue3-attrs/index.vue";
// 通过attrs传递参数 // 通过attrs传递参数
import attrs from '../components/attrs/index.vue' import attrs from '../components/attrs/index.vue'
import compositionAPI from "../components/compositionAPI.vue"; import compositionAPI from "../components/compositionAPI.vue";
// 插槽 // 插槽
import slots from '../components/slots/index2.vue' import slots from '../components/slots/index2.vue'
import FancyButton from '../components/slots/FancyButton.vue' import FancyButton from '../components/slots/FancyButton.vue'
import tree from '../components/slots/tree.vue' import tree from '../components/slots/tree.vue'
export default {
name: "createVNode", import responsive from '../components/responsive/index.vue'
components: {
jsx, export default {
attrsVue3, name: "createVNode",
attrs, components: {
compositionAPI, jsx,
slots, attrsVue3,
FancyButton, attrs,
tree compositionAPI,
}, slots,
setup(props, {emit}) { FancyButton,
function edit(val) { tree,
console.log('edit', 0); responsive
// 对返回的值做一个包装 },
emit('edit', `${val}time`) setup(props, {emit}) {
} function edit(val) {
console.log('edit', 0);
// 对返回的值做一个包装
emit('edit', `${val}time`)
}
return { return {
edit, edit,
activeKey: ref('4'), activeKey: ref('5'),
}
}
} }
}
}
</script> </script>
<!--https://blog.csdn.net/jason_renyu/article/details/122042249--> <!--https://blog.csdn.net/jason_renyu/article/details/122042249-->
<style scoped> <style scoped>
......
<template>
<a-button @click="myApiFn">发送</a-button>
<a-button @click="myApiFn2">发送</a-button>
</template>
<script>
import {myApi,getLaoWu666} from '@/api/list'
export default {
name: "dynamicAgent",
methods: {
myApiFn() {
console.log('myApi',myApi)
myApi().then(res => {
console.log('res',res)
})
},
myApiFn2() {
console.log('myApi',myApi)
getLaoWu666().then(res => {
console.log('res',res)
})
}
}
}
</script>
<style scoped>
</style>
\ No newline at end of file
此差异已折叠。
<template> <template>
<div>welcome</div> <div>
<div>welcome</div>
<demo></demo>
</div>
</template> </template>
<script> <script>
import demo from './demo.vue'
export default { export default {
name: "index", name: "index",
setup(){ components:{
demo
} }
} }
</script> </script>
......
...@@ -5,6 +5,8 @@ import * as path from 'path' ...@@ -5,6 +5,8 @@ import * as path from 'path'
// https://coding.imooc.com/learn/questiondetail/4a9DdYaWGp56lpe0.html // https://coding.imooc.com/learn/questiondetail/4a9DdYaWGp56lpe0.html
// mock // mock
import {viteMockServe} from 'vite-plugin-mock' import {viteMockServe} from 'vite-plugin-mock'
const dynamicProxy = require('./environments/proxy.js')
console.log('dynamicProxy',dynamicProxy);
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [
...@@ -14,9 +16,11 @@ export default defineConfig({ ...@@ -14,9 +16,11 @@ export default defineConfig({
}) })
], ],
server: { server: {
port: 3000, port: 8888,
open: true, open: false,
proxy: { proxy:dynamicProxy.proxy,
disableHostCheck: true,
// proxy: {
// 代理配置 // 代理配置
// '/api': { // '/api': {
// target: 'http://localhost:3000', // target: 'http://localhost:3000',
...@@ -24,13 +28,13 @@ export default defineConfig({ ...@@ -24,13 +28,13 @@ export default defineConfig({
// secure:false,//解决自签名证书错误 // secure:false,//解决自签名证书错误
// rewrite: (path) => path.replace(/^\/api/, ''), // rewrite: (path) => path.replace(/^\/api/, ''),
// }, // },
'/Api': { // '/Api': {
target: 'http://localhost:8080', // target: 'http://localhost:8080',
changeOrigin: true,//允许跨域 // changeOrigin: true,//允许跨域
secure:false,//解决自签名证书错误 // secure:false,//解决自签名证书错误
rewrite: (path) => path.replace(/^\/Api/, ''), // rewrite: (path) => path.replace(/^\/Api/, ''),
}, // },
}, // },
}, },
resolve: { resolve: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册