Instance Vue if element exists?

前端 未结 2 670
长情又很酷
长情又很酷 2021-02-13 00:17

I\'m building an app that a page has some vms, in others not. When we change from one page to another show the following warning:

[Vue warn]: Cannot find element:

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-13 00:40

    There are no issues just leaving it as is. This is just a warning that only runs when debug mode is on, so you should have it turned off in production anyway.

    If you want to get rid of it, just check if the element exists before launching Vue -

    if(document.getElementById("element-id")){
      new Vue({...})
    }
    

    Ref: How to check if element exists in the visible DOM?

提交回复
热议问题