滚动条滚动到相应位置
let top = document.getElementById('remark').offsetTop
window.scrollTo({ top: top, behavior: 'smooth' })
监听滚动条滚动事件
mounted() {
window.addEventListener('scroll', this.handleScroll) // 监听页面滚动
},
methods: {
handleScroll() {
const scrollTop =
window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
console.log(scrollTop)
}
},
//由于是在整个window中添加的事件,所以要在页面离开时摧毁掉,否则会报错
beforeDestroy() {
window.removeEventListener('scroll', this.handleScroll)
}
浏览器判断
const ua = window.navigator.userAgent.toLowerCase()
const new_ie = ua.indexOf('trident/')
//兼容ie11和360兼容模式
if(window.navigator.mimeTypes[40] || !window.navigator.mimeTypes.length){
console.log('此为360兼容模式')
}
if (new_ie !== -1) {
console.log('此为ie9以上')
}
回车发送
<el-input
v-model="chat"
resize="none"
:autosize="{ minRows: 2, maxRows: 5 }"
placeholder="输入问题,换行可通过shift+回车"
type="textarea"
@input="change"
@keydown.native="keydown"
/>
keydown(e) {
if (!e.shiftKey && e.keyCode === 13) {
e.cancelBubble = true // ie阻止冒泡行为
e.stopPropagation() // Firefox阻止冒泡行为
e.preventDefault() // 取消事件的默认动作换行
// 以下处理发送消息代码
this.sendMsg()
}
},