最近在用vue開發一個商品列表頁,因需要根據請求回的字段是否有內容來顯示隱藏該字段,
但因為vue異步加載導致顯示隱藏方法不起作業(主要是判斷條件取不到頁面渲染內容),圍觀了vue生命周期后發現updated方法很好用
$(document).ready(function () { switchList(); }); //展示接口請求 function switchList() { $.ajax({ type:"POST", timeout:3000, url:"../../../static/b2b-reception/data/switchList.json", success:function (obj) { lineListId.todos=obj; tabListId.todos=obj; } }) } //列狀展示循環渲染 var lineListId = new Vue({ el: '#line-list', data: { todos:[] }, updated: function () { newIcon(); } }); //新品標簽顯示隱藏 function newIcon() { $(".weui-mark-vip").each(function () { if($(this).find("span").text()==""){ $(this).hide(); } console.log($(this).find("span").text()); }) }