1,
select标签(二级联动,两种解决方案,Vue计算属性改变小类的option;添加change事件)
2,
滚动条消失(再在外层套个div,overflow:hidden;width:100px;子层div,overflow-y:scroll;width:126px;多出的26px则掩盖父级滚动条宽度)
3,
textarea标签特点(input标签不能设置自动换行,只能用textarea,默认文本提示placeholder;用div模拟:contenteditable属性;但是在Firefox下聚焦时候会有虚框,解决办法:outline:0)
4,
vue-router(hash(带有#,兼容所有浏览器),history(不带#,IE9不兼容))
5,
flex (flex兼容IE11,以下不兼容)
6,
刚到新公司,拉代码:首先要有自己的ssh才可以成功clone
cd ~/.ssh (如果不存在则执行第二三四条语句)
mkdir ~/.ssh
git config --global user.name
git config --global user.email
ssh-keygen -t rsa -C 'user.email'
7,
clone代码后,启动vue项目时,报错:npm: no such file or directory, scandir '.../node_modules/node-sass/vendor'
查找原因:node_modules/node-sass下竟然没有vendor模块,天啊,安装依赖npm install 时候竟然没有安装上,只好重新安装一次node-sass模块(npm rebuild node-sass ),启动项目ok。
8,
修改了配置文件,一定要重新启动项目,不然不起作用。
9,
window.location.href:当URL
https://www.jianshu.com:8080/p/c9324d237a8e?id=‘111’
window.location.protocol:协议
https
window.location.host:域名+端口
www.jianshu.com:8080
window.location.hostname:域名
www.jianshu.com
window.location.port:端口
8080
window.location.pathname:路径部分
/p/c9324d237a8e
window.location.search:请求的参数
?id=XXX
window.location.origin:参数之前的URL
https://www.jianshu.com/p/c9324d237a8e
10,
this.route.params的区别
query对应的是path
{
path: '/mtindex',
component: mtindex,
children: [
path: ':id',
component: detail
]
}
//传递参数
this.$router.push({
path: '/mtindex/detail', query: {id: item.id}
})
//获取参数
this.$route.query.id
//url的表现
localhost:8080/#/mtindex/detail?id=1
params对应的是name
{
path: '/mtindex',
component: mtindex,
children: [
path: ':id',
name: 'detail',
component: detail
]
}
//传递参数
this.$router.push({
name: 'detail', parame: {id: item.id}
})
//获取参数
this.$route.params.id
//url的表现
localhost:8080/#/mtindex
11,
列可以设置 :formatter="formatterColumn",对列的值进行处理
//状态改成汉字
formatterColumn(row, column) {
switch(row.IsAudit){
case 0:
return '未通过';
break;
1:
return '审核通过';
break;
10:
return '待审核';
break;
}
}
12,
promise.all([asyncTask1,asyncTask2,asyncTask3])
虽然是异步处理task,但是最后resultList仍然会一一映射到list里边。resultList[result1,result2,result3]。
Promise.all([
new Promise(function(resolve, reject) {
resolve(1)
}),
new Promise(function(resolve, reject) {
resolve(2)
}),
new Promise(function(resolve, reject) {
resolve(3)
})
]).then(arr => {
console.log(arr) // [1, 2, 3]
}).catch(e=>{
console.log(2)//promise.all参数若有一个存在reject,就会直接执行.catch,不会执行.then
})
var p1 = Promise.resolve(1),
p2 = Promise.resolve(2),
p3 = Promise.resolve(3);
Promise.all([p1, p2, p3]).then(results => {
console.log(results);//[1,2,3]
})
promise.race([asyncTask1,asyncTask2,asyncTask3]);
Promise.race([
new Promise(function(resolve, reject) {
setTimeout(() => resolve(1), 1000)
}),
new Promise(function(resolve, reject) {
setTimeout(() => resolve(2), 100)
}),
new Promise(function(resolve, reject) {
setTimeout(() => resolve(3), 10)
})
]).then(value => {
console.log(value) // 3
})
只要有一个实例有resolve或者reject,其他实例就不执行了。
13,
点击按钮,点击多次时候会不停发送请求
方法一:点击一次后disable按钮,但是当发现有需要修改的地方,修改后再次点击,发现已经disable了。所以在验证当时候还要取消disable,总之,很麻烦。
方法二:vue中有lodash。引入import _ from lodash
postAction=_.debounce(this.sendajax,500)
在500这个时间段,不论点击多少次,都只请求一次。
14,
vue中props传递数据是单向传递,父组件中的数据传递到子组件,子组件props接收后不能修改,违背了单向数据流到设计原则。
方法一:直接emit('update:title', newTitle)触发事件,父组件可以监听这个事件并且根据需要更新一个本地的数据。使用.sync。
:title.sync="doc.title"
15,
slot:子组件中可以用<slot>标签插槽并且name属性,父组件中根据slot属性是否等于子组件中name值来判断插入到哪个插槽。
16,移动端项目在手机端进行本地调试
1)确保手机和电脑在同一局域网(链接统一无线)
2)在终端输入ifconfig,找到ip地址
3)在手机端输入 http://...:8080网址请求
17,
vue数据初始化和生命周期的关系
https://github.com/vuejs/vue/blob/dev/src/core/instance/index.js vue源码
1)实例化时候_init函数初始化各个功能
2)在_init函数中初始化顺序如下:
3)initState函数中对props,data, computed,methods进行了初始化。所以都是在beforeCreated和created之间完成的
18,
导出查询数据功能实现
提交form 表单
<form :action="exportFileUrl" target="downloadIframe" method="post" ref="exportFile">
<input type="text" v-for="(val, key) in exportParamObj" :name="key" :value="val"
</form>
<iframe name="downloadIframe" id="downloadIframe" ref="iframe"></iframe>
setTimeout(() => {
this.$ref.exportFile.submit();
}, 20)
action:URL当提交表单时向何处发送表单数据;
target:在何处打开URL
method:规定用于发送 form-data 的 HTTP 方法。
input标签中的内容是提交表单的数据,也就是请求的参数。
19,
mac上iTerm显示分支及高亮
效果如下:
1)切换到etc目录下
sudo vim /etc/profile
2)把如下代码加入
find_git_branch () {
local dir=. head
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head = ref:\ refs/heads/* ]]; then
git_branch=" (${head#*/*/})"
elif [[ $head != '' ]]; then
git_branch=" → (detached)"
else
git_branch=" → (unknow)"
fi
return
fi
dir="../$dir"
done
git_branch=''
}
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
black=$'\[\e[1;30m\]'
red=$'\[\e[1;31m\]'
green=$'\[\e[1;32m\]'
yellow=$'\[\e[1;33m\]'
blue=$'\[\e[1;34m\]'
magenta=$'\[\e[1;35m\]'
cyan=$'\[\e[1;36m\]'
white=$'\[\e[1;37m\]'
normal=$'\[\e[m\]'
PS1="$white[$white@$green\h$white:$cyan\W$yellow\$git_branch$white]\$ $normal"
3)执行命令
source /etc/profile
20,
css实现td表格中文字居中后左对齐
效果图如下:
实现思路:td中嵌套个div,td中文字设置居中
text-align: center
,div中文字设置左对齐:
text-align: left;
position: relative;
left: 50%;
margin-left: div宽度的一半
21,
vue中watch踩坑
1)项目中,我想监听的内容是在初始化赋值之后再进行监听,而不是上来就用data中返回的值和初始化值进行比较。
解决办法:
Api.config.queryConfigInfo({
periodName: this.periodName
})
.then( data => {
this.info = data;
this.$watch('info', this.changeinfo, {deep: true});
})
赋值之后,进行监听。
2) watch监听obj的时候,如果想要监听到obj的属性是否变化,需要深度监听,deep:true;或者‘obj.attr‘进行监听。
val和oldVal相同:
3)vue中想给已有的对象增加两个或者多个新的属性,需要这样做:
this.userProfile = Object.assign({}, this.userProfile, {
age: 27,
favoriteColor: 'Vue Green'
})
而不是:
Object.assign(this.userProfile, {
age: 27,
favoriteColor: 'Vue Green'
})
22,
向有序数组中插入一个数
var arr = [1, 5, 7, 11, 88];
//var arr = [1,5, 6,7,11,88]要得到结果
//把6按照顺序插入到列表中
var index = 0;
var num = 6;
for (var i = 0; i < arr.length; i++) {
if (arr[i] >= num) {
index = i;
break;
}
}
arr.splice(index, 0, num)