Vue开发中遇到的问题与解决方案(一)
2018-01-03 16:55
323 查看
vue生命周期函数:http://www.zhimengzhe.com/Javascriptjiaocheng/236707.html
1、在watch或者created里面操作dom,用this.$nextTick(function(){
xxxx
})
2、class动态绑定 三元写法:
:class="[isShowTab?'showTab':'noShowTab']"
3、vue获取后端数据应该在created还是mounted方法:
看情况了,一般放到created里面就可以了,这样可以及早发请求获取数据,如果有依赖dom必须存在的情况,就放到mounted(){this.$nextTick(() => { /* code */ })}里面
4、watch里面函数写法不同this指代不同
(1)
tabName: (newVal) => {
console.
4000
log(this, 'this')
}
(2)
tabName: function (newVal)
{
console.log(this, 'this')
}
上面的方法(1)不能用this.$nextTick,会报错,方法(2)可以用this.$nextTick
5、
window.addEventListener('scroll',function(){ 在这个里面使用this.data 提示未定义,请问如何访问data(){return {}}的数据
试试 用 ()=> {}或者:
this.$data或者:
let vm =this ;window.addEventListener('scroll',function(vm ){})这样 你就能 访问 vue 的 this
6、render函数的使用
render:function(createElement){
return createElement(
'h'+this.level,
{
'class':{
show:true,
hide:false,
},
style:{
width:'200px',
height:'400px',
background:'red',
},
attrs:{
name:'h-ex',
id:'h-id'
},
props:{
myprops:true,
},
on: {
click: function(event){
alert(this.num)
}
},
nativeOn:{
click:function(event) {
alert(1111)
}
}
},
[
this.$slots.myslot,
createElement('div',{
domProps:{
innerHTML:'holle render'
}
})
]
)
}
1、在watch或者created里面操作dom,用this.$nextTick(function(){
xxxx
})
2、class动态绑定 三元写法:
:class="[isShowTab?'showTab':'noShowTab']"
3、vue获取后端数据应该在created还是mounted方法:
看情况了,一般放到created里面就可以了,这样可以及早发请求获取数据,如果有依赖dom必须存在的情况,就放到mounted(){this.$nextTick(() => { /* code */ })}里面
4、watch里面函数写法不同this指代不同
(1)
tabName: (newVal) => {
console.
4000
log(this, 'this')
}
(2)
tabName: function (newVal)
{
console.log(this, 'this')
}
上面的方法(1)不能用this.$nextTick,会报错,方法(2)可以用this.$nextTick
5、
window.addEventListener('scroll',function(){ 在这个里面使用this.data 提示未定义,请问如何访问data(){return {}}的数据
试试 用 ()=> {}或者:
this.$data或者:
let vm =this ;window.addEventListener('scroll',function(vm ){})这样 你就能 访问 vue 的 this
6、render函数的使用
render:function(createElement){
return createElement(
'h'+this.level,
{
'class':{
show:true,
hide:false,
},
style:{
width:'200px',
height:'400px',
background:'red',
},
attrs:{
name:'h-ex',
id:'h-id'
},
props:{
myprops:true,
},
on: {
click: function(event){
alert(this.num)
}
},
nativeOn:{
click:function(event) {
alert(1111)
}
}
},
[
this.$slots.myslot,
createElement('div',{
domProps:{
innerHTML:'holle render'
}
})
]
)
}
相关文章推荐
- vue开发中遇到的问题与解决方案(二)
- vue开发中遇到的问题与解决方案(三)
- j2ee 使用tomcat开发网站需要访问中文名的资源遇到的问题解决方案。。
- 开发中遇到的问题及解决方案总结一
- 我在开发AJAX过程中遇到的问题及解决方案,分享给大家~
- Android开发过程遇到的安装好的APP打开程序崩溃,或者安装后应用列表里没有的问题及解决方案
- NDK开发——Android Studio中开发NDK遇到的错误问题与解决方案汇总
- 记录学习《0Day安全》路上遇到的问题解决方案 -- 开发shellcode的艺术!
- 深度学习开发环境搭建遇到的问题及解决方案
- 用TI CC2530DK开发时,用light swtich例子会遇到的一个问题和解决方案
- 安卓开发中遇到耗电量高的问题解决方案
- android开发中遇到的一些问题及解决方案
- android开发过程遇到的问题和解决方案(不断更新)
- c++开发过程中遇到的问题及解决方案
- JSP开发过程遇到的中文乱码问题及解决方案
- 【Richie Zhu】android开发时使用Android模拟器经常遇到连不上、连一次掉一次等诸多问题的解决方案
- 使用heroku开发应用时连接数据库遇到的问题及解决方案
- 数据库开发遇到的问题及解决方案(个人日志、持续更新)
- JSP开发过程遇到的中文乱码问题及解决方案
- .Net开发工作中常遇到的一些问题及解决方案