Vue——常见问题
-
内置指令获取 event 对象
<li @click="change($event)">哈哈哈</li> // .. 调用 change(event)
-
自定义指令获取组件数据
// .... 通过vnode 访问绑定数据 vnde.elm vnode.context._data
-
window 事件注册:大多通过在生命周期的 mouted 中注册 window 事件,在 beforeDestroy 销毁事件
mounted () { // this.$nextTick(() => { skrollr.init() // }) }, beforeDestroy () { let instance = skrollr.get() instance.destroy() }
ready() { window.addEventListener('focus', this.handleWinFocus); }, beforeDestroy() { window.removeEventListener('focus', this.handleWinFocus); }
-
$listeners: https://cn.vuejs.org/v2/guide/components-custom-events.html#将原生事件绑定到组件
-
兼容性问题:目前普遍认为只能兼容到 IE9 https://segmentfault.com/q/1010000011596189
-
图片引用问题:https://blog.csdn.net/MoLvSHan/article/details/78204972
data() { return { shouye:'url(' + require('../../assets/images/shouye/index2x.png') + ')', fenlei:'url(' + require('../../assets/images/shouye/fenlei2x.png') + ')', search:'url(' + require('../../assets/images/shouye/search2x.png') + ')', shopcart:'url(' + require('../../assets/images/shouye/gouwuche2x.png') + ')', mine:'url(' + require('../../assets/images/shouye/I2x.png') + ')' } }
methods: { loadImg(tableListItem) { if (!tableListItem.picture) return `${require('@/assets/Bimg_01.png')}`; return tableListItem.picture; } }