index.vue 4.2 KB
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title></title>

    <link href="https://fonts.googleapis.com/css?family=Nunito:400,600,700" rel="stylesheet">

    <!-- Import style -->
    <link rel="stylesheet" href="https://unpkg.com/element-plus@2.10.1/dist/index.css" />
    <!-- Import Vue 3 -->
    <script src="https://unpkg.com/vue@3.5.16/dist/vue.global.js" type="application/javascript"></script>
    <!-- Import component library -->
    <script src="https://unpkg.com/element-plus@2.10.1/dist/index.full.js" type="application/javascript"></script>
    <script src="https://unpkg.com/@element-plus/icons-vue@2.3.1/dist/index.iife.min.js" type="application/javascript"></script>

    <script src="https://unpkg.com/axios@1.9.0/dist/axios.min.js" type="application/javascript"></script>
    <!--请不要删除下面注释代码-->
    <!--{#link#}-->
</head>
<body>
<div id="app">
    <component-main></component-main>
</div>
</body>
</html>
<!--请不要删除下面注释-->
<!--{#script.src#}-->
<style>
body{
    margin: 0;
    padding:0;
    font-size: 12px;
    font-weight: unset;
}
.el-table{width: 100%;}
.mr-2{margin-right: 2rem;}
.mr-1{margin-right: 1rem;}
.w-100{width: 100%;}
</style>
<!--请不要删除下面注释-->
<!--{#style#}-->
<script type="application/javascript">
// 针对谷歌浏览器调试是出现的 No resource with given URL found
//# sourceURL=dynamicScript.js

</script>
<!--请不要删除下面注释-->
<!--{#script#}-->
<script type="application/javascript">

const VueApp = {
    data() {
        return {

        }
    },
    components:{
        "component-main":"@component(<--{#component_main#}-->)"
    }
    ,created(){

    }
}

// 减少写法
const elMsg = ElementPlus.ElMessage;
const elMsgBox = ElementPlus.ElMessageBox;

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
    // config.headers['X-CSRF-TOKEN'] = _CSRF_TOKEN_;
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    // console.log(response);
    // 是否弹出消息
    if(response.data.message){
        if(response.data.status === 200){
            elMsg.success(response.data.message);
        }else {
            elMsg.error(response.data.message);
        }
    }

    return response;
}, function (error) {
    // console.log(error)
    if(error.response.data && error.response.data.message){
        elMsg.error(error.response.data.message);
    }else {
        elMsg.error(error.message);
    }

    // 对响应错误做点什么
    return Promise.reject(error);
});

/**
 * 对axios的再次封装
 */
class axiosPackage {
    #startCall
    start(call){
        this.#startCall = call;
        return this;
    }
    post(url, data = {}){
        return this.#result(axios.post(url, data));
    }
    get(url){
        return this.#result(axios.get(url))
    }
    delete(url){
        return this.#result(axios.delete(url))
    }
    #result(res){
        return res.then(response=> {
            return response.data
        }).catch(e=>{
            let data = {status:500};
            data.e = e;
            return data;
        })
    }
}
// 使用函数 进行 实例
function ajax(){
    return new axiosPackage()
}

/**
 * 深拷贝
 * @param obj
 * @returns {*}
 */
function copy (obj) {
    let newObj = null
    if (typeof obj === 'object' && obj !== null) {
        newObj = obj instanceof Array ? [] : {}
        for (let i in obj) {
            newObj[i] = typeof obj[i] === 'object' ? copy(obj[i]) : obj[i]
        }
    } else {
        newObj = obj
    }
    return newObj
}



// 创建应用
const app = Vue.createApp(VueApp);
// 加载ele插件
app.use(ElementPlus);

// 使用图标
// app.use(ElementPlusIconsVue); // 这个加载方式不可以
// 下面是正确的加载方式,仅适用于 cdn方式
for ([name, comp] of Object.entries(ElementPlusIconsVue)) {
    app.component(name, comp);
}

const vmElm = app.mount('#app');
</script>