# vue-notes **Repository Path**: fqcto/vue-notes ## Basic Information - **Project Name**: vue-notes - **Description**: vue开发中的实战经验笔记 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-08-02 - **Last Updated**: 2021-11-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Vue开发笔记 # gitlab上克隆远程分支到本地 ``` 修改配置 git config --global user.name git config --global user.email 如:git config --global user.name "yang" git config --global user.email "yang@XX.com" 看我的操作: 进入到想要放项目的目录,例中的git_out目录就是我放项目的目录克隆远程项目 git clone 如:git clone http://XXX.XXX/sq-group/XXX.git克隆完成之后,可以看见项目名称,进去项目之后,可以看见一些git相关文件进入项目所在(即.git所在文件夹)内 查看远程分支 git branch -r 如:建立本地对应分支 git checkout --track 或者 git checkout -b 如:git checkout --track origin/yang ``` ## el-table表格自适应高度 ``` tableHeight: 50 this.$nextTick(function() { this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 150; console.log("1") console.log(this.tableHeight) console.log("2") // 监听窗口大小变化 let self = this; window.onresize = function () { self.tableHeight = window.innerHeight - self.$refs.table.$el.offsetTop - 150; } }) ``` ## css3 置灰filter: grayscale(100%) ``` .gray { -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); -o-filter: grayscale(100%); filter: grayscale(100%); //上面代码是兼容火狐与谷歌的样式 //下面代码是兼容ie9以下浏览器的样式,包括ie9 filter: gray; } ``` ## input只能输入正整数 ``` ``` # Vue 复制到粘贴板 > 使用 vue-clipboard2 复制到粘贴板 ## 1.安装vue-clipboard2 > npm install --save-dev vue-clipboard2 ## 2.main.js中添加 > 复制到粘贴板插件 ## import VueClipboard from 'vue-clipboard2' > VueClipboard.config.autoSetContainer = true ## Vue.use(VueClipboard) ### 好多代码其实用重复无用浪费资源,记住所有块级元素的div都要写 overflow: hidden 不然影响文本流 ## 3.文件中使用 ``` ``` ## 插槽 ``` ``` #### 插槽--可以任意调取值到指定行进行判断操作 ``` ``` #### 2 ``` ``` ###3 还可以插入过滤器 ``` ``` ### vue中如何传参--aa(props.row.id,props.row.adviserId)-- ``` ``` #### 判断为何值时,审核显示或隐藏 ``` ``` #### 4过滤器案例 ``` filters:{ levelFilter(val){ switch(val){ case 'BDY':return "北斗音";break; case 'CITY':return "城市合伙人";break; case 'AREA':return "区域合伙人";break; case 'ALONE':return "独立合伙人";break; case 'NORMAL':return "NORMAL";break; } } } ``` #### 禁止缩放 ``` 在APP.vue里面写 ``` #### 子组件和全局组件 ### 子组件 * 父组件中引入和声明 * import xxx from 'xxxx'; ---引入 * components:{ 'xx':xx } ---声明 ### 全局组件 * 全局组件,使用更为方便,不需要声明,直接使用 * 在main.js 中引入一次,在main.js 中使用 `vue.component('组件名','组件对象');` * 所有的组件就可以直接通过组件名使用 #### 父传子 * 父组件通过子组件的属性将值进行传递 -- 方式有2: + 常量: prop1="常量值" + 变量: :prop2="变量名" * 子组件需要声明 -- 根属性props:['prop1','prop2'] -- 在页面中直接使用{{prop1}} -- 在js中如何使用?-- this.prop1获取 #### vueBus的通信使用实现子组件通信父组件 * 通过new Vue()这样的一个vueBus对象,来$on('事件名',fn(prop1,prop2)) * 另一个组件引入同一个vueBus,来$emit('事件名',prop1,prop2) #### 看文档的对象分类 * 1:全局的代表Vue.的 * 2: 实例的代表this.或者new Vue(). * 3: 选项代表 new Vue()的参数 * 或者 export default 里边的属性 ### vue 登陆时回车键和点击都可以触发登陆事件 ### vue 登陆时回车键和点击都可以触发登陆事件 ### vue 登陆时回车键和点击都可以触发登陆事件 ### 在表单最后的输入框添加(是最后的输入框) @keyup.enter.native="submitForm(‘ruleForm2’) 事件 ``` ``` #### 登陆按钮添加 @click="submitForm(‘ruleForm2’)"事件 ``` 登录 ``` #### 表单 prop写法 可适用于修改项 ``` this.roleForm = { stockName: row.stockName, id: row.id, idCard: row.idCard, phone: row.phone }; ``` #### el-table-column的筛选 下拉框 ``` ``` ##### 获取标签内容 ``` filterIsSale(value, row) { return row.isSale == value; }, ``` #### el-upload ``` if (!(this.shopForm.picture instanceof Array)) { this.shopForm.picture = this.shopForm.picture .split(",") .filter(Boolean); } let selectCode = this.filterAdcode(this.shopForm.adcode); this.$nextTick(() => { this.$refs.cascaderForm.currentValue = selectCode; this.shopForm.picture.forEach(item => this.fileList.push({ url: this.imgUrl + item }) ); }); ``` #### el-upload 总结 ``` 点击上传 ``` ##### 在编辑的时候 ###### 编辑店铺 ``` editStore() { if (!this.multipleSelection) { return this.$message.warning("请选择操作对象"); }else{ this.isShopForm = true this.shopForm = this.multipleSelection } if (!(this.shopForm.picture instanceof Array)) { this.shopForm.picture = this.shopForm.picture .split(",") .filter(Boolean); } let selectCode = this.filterAdcode(this.shopForm.adcode); this.$nextTick(() => { this.$refs.cascaderForm.currentValue = selectCode; this.shopForm.picture.forEach(item => this.fileList.push({ url: this.imgUrl + item }) ); }); }, /* 对城市编码进行分割 */ filterAdcode(val) { let length = `${val}`.length; val = val.toString(); let arr = []; if (length < 2) { arr.push(val); } else if (length > 2 && length <= 4) { arr.push(val.substring(0, 2), val); } else if (length > 4 && length <= 6) { arr.push(val.substring(0, 2), val.substring(0, 4), val); } else { arr.push( val.substring(0, 2), val.substring(0, 4), val.substring(0, 6), val ); } return arr; }, /* 图片上传成功 */ handleAvatarSuccess(res) { if (res.errorCode == 0) { if (!this.shopForm.picture) { this.shopForm.picture = []; } this.$message.success("上传图片成功"); this.shopForm.picture.push(res.bizContent.code); } else { this.$message.error("图片上传失败"); this.$nextTick(() => { this.$refs.uploadPictures.uploadFiles.pop(); }); } }, /* 图片预览 */ handlePictureCardPreview(res) { this.preImg = res.url; this.imgDialogVisible = true; }, /* 图片移除 */ removeHandle(res) { let data = res.response; if (data) { this.shopForm.picture.forEach((item, i) => { if (item == data.bizContent.code) { this.shopForm.picture.splice(i, 1); this.$message.success("图片删除成功"); return; } }); } else { this.shopForm.picture.forEach((item, i) => { if (this.imgUrl + item == res.url) { this.shopForm.picture.splice(i, 1); this.$message.success("图片删除成功"); return; } }); } }, ``` ### expand 展开子表 #### 一级数据接口请求 得出一级数据后 遍历该数据强塞想要的字段格式并格式化--- 强塞 字段 ``` records.forEach(item=>{ item.children = [] }) ``` #### 一级自带事件 @expand-change="expand()" ``` async expand() { if (this.$refs.table.store.states.expandRows.length > 1) { this.$refs.table.store.states.expandRows[0] = this.$refs.table.store.states.expandRows[1]; this.$refs.table.store.states.expandRows.pop(); } if (this.$refs.table.store.states.expandRows.length > 0) { try { const { data: { bizContent: { records, total } } } = await this.$http.get( "/goodsAttributeValue/getGoodsAttributeValueList?size=10000", { params: { id: this.$refs.table.store.states.expandRows[0].attrKey } } ); this.keyTableData.forEach(item=>{ if(item.attrKey === this.$refs.table.store.states.expandRows[0].attrKey){ item.children = records } }) // console.log(this.$refs.table) console.log(this.keyTableData) // this.attrTableData = records; } catch (e) { window.console.log(e); } } }, ``` ### :row-class-name="tableRowClassName" #### 列的颜色 ---外部引入单独css文件 ``` @import '../../assets/css/common.css tableRowClassName({row, rowIndex}) { switch((rowIndex+1)%2){ case 1: return 'warning-row'; case 0: return 'success-row'; } }, .el-table .warning-row { background: oldlace; } .el-table .success-row { background: #f0f9eb; } ``` ### 单独独有文件 级联地址选择器 > import Address from "../../assets/data/data.json"; > import { cityFilter} from "../../assets/js/cityFilter"; ``` ``` ### // 地址选择 ``` getAddressCode(e) { console.log(e) let code = e[e.length - 1]; // if (this.queryForm.adCode == code) return; // this.queryForm.adCode = code; console.log(code) this.getAddrCode = code } ``` ### computed监听 ``` computed: { Address(){ return cityFilter(Address) }, globalStoreId() { return this.$store.state.globalStoreId; } }, ``` #### 设置form表内部的值(另一种写法) ``` let _this = this; .then(function(response) { _this.$set( _this.form,"costPrice",response.data.bizContent.costPrice); _this.$set(_this.form, "price", response.data.bizContent.price); _this.$set(_this.form, "vipPrice", response.data.bizContent.vipPrice); _this.$set(_this.form,"total", response.data.bizContent.total); }) ``` #### 富文本框- ``` ``` ### 富文本工具栏配置 > 富文本工具栏配置 ```const toolbarOptions = [ ["bold", "italic", "underline", "strike"], // toggled buttons ["blockquote", "code-block"], [{ header: 1 }, { header: 2 }], // custom button values [{ list: "ordered" }, { list: "bullet" }], [{ script: "sub" }, { script: "super" }], // superscript/subscript [{ indent: "-1" }, { indent: "+1" }], // outdent/indent [{ direction: "rtl" }], // text direction [{ size: ["small", false, "large", "huge"] }], // custom dropdown [{ header: [1, 2, 3, 4, 5, 6, false] }], [{ color: [] }, { background: [] }], // dropdown with defaults from theme [{ font: [] }], [{ align: [] }], ["link", "image", "video"], ["clean"] // remove formatting button ]; ``` ### 配置参数 ``` editorOption: { modules: { toolbar: { container: toolbarOptions, //工具栏 handlers: { image: function(value) { if (value) { // 调用element图片上传 document.querySelector("#upLoadBtn").click(); } else { this.quill.format("image", false); } } } } } }, ``` #### 全局注册组件 > const pagination =()=>import('./components/pagination') ##### Vue.component('pagination',pagination) > ##### element的表单验证清楚--防止下次提交表单验证规则缓存 - clearValidate() - ##### 记住,要渲染页面后再执行,不然找不到虚拟dom,最好用this.$nextTick( () => this.$refs.baseInfoInitConfig.clearValidate()) ##### 表格列的时候-加:key 可消除表格抖动改变样式 ``` ``` ### 全屏事件 ``` handleFullScreen() { let element = document.documentElement; if (this.fullscreen) { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.webkitCancelFullScreen) { document.webkitCancelFullScreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } } else { if (element.requestFullscreen) { element.requestFullscreen(); } else if (element.webkitRequestFullScreen) { element.webkitRequestFullScreen(); } else if (element.mozRequestFullScreen) { element.mozRequestFullScreen(); } else if (element.msRequestFullscreen) { // IE11 element.msRequestFullscreen(); } } this.fullscreen = !this.fullscreen; } ``` ### echart 另一种导入方式,script方式 ``` oneEcharts: '', twoEcharts: '', threeEcharts: '', created() window.onresize = () => { if (this.oneEcharts) this.oneEcharts.resize(); if (this.twoEcharts) this.twoEcharts.resize(); if (this.threeEcharts) this.threeEcharts.resize(); }; mounted() const s = document.createElement('script'); s.type = 'text/javascript'; s.onload = () => { this.getEchartsData(); }; s.src = 'https://resource.oss.yatiku.com/activity/answerFile/echarts.common.min.js'; document.body.appendChild(s); initEcharts () { let dom = document.querySelector('#dom'); let option = { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, title: { text: '考试分类统计(总计)', left: 'center', textStyle: { color: 'white' } }, legend: { textStyle: { color: 'white' }, data: ['', '', '', '提问量', '超时量', '满意量'] }, grid: { left: '3%', right: '10%', containLabel: true }, xAxis: { show: false }, yAxis: { type: 'category', data: this.putQuestionsData.yDataLable, axisLabel: { textStyle: { color: '#fff' } } }, series: [ { name: '提问量', type: 'bar', data: this.putQuestionsData.questionsNumber, barGap: '0', label: { show: true, color: '#fff', position: 'right', formatter: '{c}' // offset: [10, 10] }, itemStyle: { normal: { color: '#ff7e00' } } }, { name: '超时量', type: 'bar', data: this.putQuestionsData.timesOutNumber, itemStyle: { normal: { color: '#9933cc', label: { show: true, color: '#fff', position: 'right', formatter: '{c}' } } } }, { name: '满意量', type: 'bar', data: this.putQuestionsData.satisfiedNumber, itemStyle: { normal: { color: '#ff33ff', label: { show: true, color: '#fff', position: 'right', formatter: '{c}' } } } } ] }; this.oneEcharts = echarts.init(dom); this.oneEcharts.setOption(option); }, initTop () { let dom = document.querySelector('#topDom'); this.twoEcharts = echarts.init(dom); let option = { tooltip: { trigger: 'axis', axisPointer: { // 坐标轴指示器,坐标轴触发有效 type: 'shadow' // 默认为直线,可选为:'line' | 'shadow' } }, title: { text: '教师收益排行(TOP10)', left: 'center', textStyle: { color: 'white' } }, grid: { left: '0%', right: '4%', bottom: '0%', containLabel: true }, xAxis: { type: 'category', data: this.teacherData.yDataLable, axisTick: { alignWithLabel: true }, 'axisLabel': { interval: 0, rotate: 45, margin: 15, textStyle: { color: '#fff' } } }, yAxis: [ { type: 'value' } ], series: [ { name: '余额', type: 'bar', stack: '总量', label: { normal: { show: true, position: 'inside', formatter: function (a, b, c) { let value = a.value > 1000 ? `${(a.value / 1000).toFixed(1)}K` : a.value.toFixed(0); return value; } } }, itemStyle: { normal: { color: '#999900' } }, data: this.teacherData.balanceList }, { name: '提现', type: 'bar', stack: '总量', label: { normal: { show: true, position: 'inside', formatter: function (a, b, c) { let value = a.value > 1000 ? `${(a.value / 1000).toFixed(1)}K` : a.value.toFixed(0); return value; } } }, itemStyle: { normal: { color: '#66ff33' } }, data: this.teacherData.withdrawMoney } ] }; this.twoEcharts.setOption(option); }, initBottom () { let dom = document.querySelector('#bottomDom'); let option = { color: ['#3398DB'], tooltip: { trigger: 'axis', axisPointer: { // 坐标轴指示器,坐标轴触发有效 type: 'shadow' // 默认为直线,可选为:'line' | 'shadow' } }, title: { text: '教师抢答量排行(TOP10)', left: 'center', textStyle: { color: 'white' } }, grid: { left: '0%', right: '4%', bottom: '0%', containLabel: true }, xAxis: { type: 'category', data: this.answerData.yDataLable, axisTick: { alignWithLabel: true }, 'axisLabel': { interval: 0, rotate: 45, margin: 15, textStyle: { color: '#fff' } } }, yAxis: [ { type: 'value' } ], series: [ { name: '抢答量', type: 'bar', data: this.answerData.answerNumber, itemStyle: { normal: { label: { show: true, color: '#fff', position: 'top', formatter: '{c}' } } } } ] }; this.threeEcharts = echarts.init(dom); this.threeEcharts.setOption(option); }, ```