vue根据url获取内容axios_vue.js - Vue2.0 使用axios获取数据后,渲染dom,如何在这之后操作dom(渲染后的)?...

问 题

在html中用axios返回的数据,渲染dom

item.text

{{item.ctitle}}

{{item.name}}

想操作渲染的dom,但是貌似不行this.nextTick()也不行,还是我用错了?

import jQuery from 'jquery'

export default {

data () {

return {

content:[]

}

},

methods : {

show () {

this.$nextTick(function () {

jQuery(".jj").hide();

jQuery(".top > div").hover(function(){

jQuery(".jj",this).slideToggle(500);

jQuery("img",this).animate({

opacity: 0.1

},1,function(){

jQuery(".top > div").mouseleave(function(){

jQuery("img",this).animate({

opacity: 1

},1)

})

});

});

});

},

getData () {

this.$http({

url: `http://192.168.1.108:3000${this.$route.path}`,

method: 'get'

}).then((res) => {

this.content = res.data;

}).catch((res) => {

console.log('error:', res)

})

}

},

beforeRouteUpdate(to, from, next) {

this.$http({

url: `http://localhost:2000/getjson${to.path}`,

method: 'get',

}).then((res) => {

this.content = res.data;

}).catch((res) => {

console.log('error: ', res);

});

next();

},

mounted() {

this.show();

this.getData();

}

}

解决方案

放在getData请求成功后就可以了

getData () {

this.$http({

url: `http://192.168.1.108:3000${this.$route.path}`,

method: 'get'

}).then((res) => {

this.content = res.data;

// 建议把nextTick写show方法外面

this.$nextTick(this.show)

}).catch((res) => {

console.log('error:', res)

})

}

},

扫一扫关注IT屋

微信公众号搜索 “ IT屋 ” ,选择关注与百万开发者在一起

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值