# 文档说明 **Repository Path**: xietb/document_description ## Basic Information - **Project Name**: 文档说明 - **Description**: No description available - **Primary Language**: JavaScript - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-12-05 - **Last Updated**: 2020-12-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 文档说明 ## 1. 查找组件方法 ``` //根据组件名查找组件 this.findComponent(componentName); ``` ``` //根据ref名查找组件 this.findRef(refName); ``` ## 2. cookie操作 ``` //先引入cookie模块 import Cookies from 'js-cookie' ``` [js-cookie详细文档请查看这里](https://www.npmjs.com/package/js-cookie) #### 2.1 基本用法 ``` Create a cookie, valid across the entire site: Cookies.set('name', 'value'); Create a cookie that expires 7 days from now, valid across the entire site: Cookies.set('name', 'value', { expires: 7 }); Create an expiring cookie, valid to the path of the current page: Cookies.set('name', 'value', { expires: 7, path: '' }); Read cookie: Cookies.get('name'); // => 'value' Cookies.get('nothing'); // => undefined Read all visible cookies: Cookies.get(); // => { name: 'value' } Delete cookie: Cookies.remove('name'); Delete a cookie valid to the path of the current page: Cookies.set('name', 'value', { path: '' }); Cookies.remove('name'); // fail! Cookies.remove('name', { path: '' }); // removed! ``` ## 3. axios ajax操作方法 #### 3.1 二次封装后的直接访问方式 第四个参数noLoading为是否显示loading图标,默认显示,noLoading=true为隐藏,noLoading=false为显示 this.common.ajax(url, params, callback, noLoading); ``` //此方法有鉴权验证 var url = "/api/auth/Login"; var params = { guid: guid }; var callback = res => { this.loading = false; if (res.Msg) { this.$message.error(res.Msg); } if (res.Result) { ... } else { ... } }; this.common.ajax(url, params, callback, true); ``` #### 3.2 ajax2没有鉴权验证 this.common.ajax2(url, params, callback, noLoading); - 用法同上面this.common.ajax #### 3.3 原生axios [axios详细文档请查看这里](https://www.kancloud.cn/yunye/axios/234845) ``` var json = "/static/abc.json"; this.axios .get(json) .then(function(response) { Object.keys(response.data).forEach(key => { the.$set(the, key, response.data[key]); }); //获得表格自定义设置 var key = "tableConfig_" + router; var fields = Cookies.get(key); if (fields) { fields = JSON.parse(fields); the.dataListOptions.fields = fields; } the.$nextTick(() => { //优先加载下拉框,然后在加载数据 the.$refs["data-list"].loadDropDown(); }); }) .catch(function(error) { console.log(error); }); ```