1.绑定多个class
v-bind:class="{className1: bool, className2:bool}"
v-bind:class="['className1', 'className2']"
2.v-on 修饰符
stop
:阻止事件冒泡
prevent
:阻止默认事件
native
:监听组件根元素的原生事件
once
:只触发一次回调
3.element-ui的MessageBox确保只提示一次
if (document.getElementsByClassName('el-message-box').length === 0 || document.getElementsByClassName('el-message-box__wrapper')[0].style.display === 'none') {
MessageBox.alert('cintent', 'title', {
confirmButtonText: '确定',
callback: action => {
}
});
}
4.axios-retry
重发次数设置无效,报错后一直重新请求
解决:0.19.0版本的axios
的锅,升级最新版0.19.2就没问题了。
5.watch 监听一个对象中的属性
watch: {
'json.name': {
handler: function() {
//do something
},
}
}
6.Avoided redundant navigation to current location: “/questions”
在router的index.js中添加下面代码
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
7.计算属性传递参数
computed: {
myFunc(){
return function(param){
///param
}
}
},
8.多个路由共用一个页面,路由变化页面不刷新
watch: {
"$route":function(to, from){
//重新调用接口,刷新
}
}