<script>
var testDemo = new Vue({
el: '#app',
data: {
// v-html会用到
vHtml: 'xxx';
},
methods: {
onClick: function() {
let vueObj = this;
this.myAjax('POST', 'http:xxx', {id: 1}, function (data) {
if (data) {
vueObj.vHtml = data;
vueObj.$nextTick(function () {
// 仅在整个视图都被渲染之后才会运行的代码
$('ul').find('a').each(function () {
$(this).attr('title', $(this).text());
})
})
}
})
},
myAjax: function(type, url, data, callback) {
try {
$.ajax({
type: type,
url: url,
data: data,
dataType: "json",
timeout: 3000,
success: function (data) {
if (data.code == 0) {
callback(data.data);
} else {
callback();
}
},
error: function (error) {
callback();
},
});
} catch (e) {
console.log(e);
} finally {
}
}
}
});
</script>
[Vue]使用$nextTick操作v-html渲染后的Dom元素
最新推荐文章于 2023-01-14 11:58:18 发布