清除存储数据
this.$storage.clear()
四元运算符
:class="index == 0? 'items': index == 1? 'flex-margin': 'sec-items-flex'"
输入框禁止输入小数点
<input @keydown.native="handleInput">
methods:{
handleInput(e) {
let key = e.key
// 不允许输入'e'和'.'
if (key === 'e' || key === '.') {
e.returnValue = false
return false
}
return true
},
}
vue编译时添加版本号
//vue.config.js
//定义版本 这是使用当前时间数 当然也可以自定义版本1.0等
const Version = new Date().getTime();
module.exports = {
// webpack配置
chainWebpack: config => {
if (process.env.NODE_ENV === 'production') {
// 给js和css配置版本号
config.output.filename('js/[name].[chunkhash].' + Version + '.js').end();
config.output.chunkFilename('js/[name].[chunkhash].' + Version + '.js').end();
config.plugin('extract-css').tap(args => [{
filename: css/[name].[chunkhash].${Version}.css,
chunkFilename: css/[name].[chunkhash].${Version}.css
}])
}
}
}
禁止蒙层下的页面还可以滚动
移动端:(1)在蒙层所在的div上加@touchmove.prevent
startScroll () { document.body.style.overflow = ''// 出现滚动条 document.removeEventListener('touchmove', this.bodyScroll, false) }
//在弹层事件中相应调用就可; PC端 弹层显示时调用stopMove()停止页面滚动,弹层消失调用 Move()开启页面滚动 //停止页面滚动 stopMove(){ let m = function(e){e.preventDefault();}; document.body.style.overflow='hidden'; document.addEventListener("touchmove",m,{ passive:false });//禁止页面滑动 }, //开启页面滚动 Move(){ let m =function(e){e.preventDefault();}; document.body.style.overflow='';//出现滚动条 document.removeEventListener("touchmove",m,{ passive:true }); }
vue修改dom样式
ref VS $refs
ref 目标对象:是单个dom元素或子组件
// 单个dom节点 // 子组件中 $refs 目标对象:任意组件都会注册$refs属性 联系:当子组件中出现有ref的引用信息时,父组件中的$refs就可以获取到该子组件的引用获取dom节点 console.log(this.refs属性,获取子组件 的dom 修改dom样式 this.$refs.singleDom.style.color = 'red'
JS获取url最后一个字段
getUrlsub: function (href) {
let index = href.lastIndexOf("\/");
let str = href.substring(index + 1,href.length);
return str
}