简体   繁体   English

vue.js找不到元素#app

[英]vue.js Cannot find element #app

learning custom plugins, I am trying to test wa virtual DOM 学习自定义插件,我正在尝试测试wa虚拟DOM

import Vue from 'vue'
import MyPlugin from '@/plugins/MyPlugin'

Vue.use(MyPlugin)

describe('MyPlugin', () => {
  let vm

  beforeEach(() => {
    vm = new Vue({
      template: '<div id="app" class="container" v-demo:hello.a.b="msg"></div>',
      el: '#app',
      data: {
        msg: 'hello!'
      }
    }).$mount()
  })

  it('should run', () => {
    Vue.myMethod()
    console.log('INNER: ', vm.$el.innerHTML)
    expect(true).to.equal(true)
  })
})

but I get an error : 但我得到一个错误:

ERROR LOG: '[Vue warn]: Cannot find element: #app' 错误日志:'[Vue警告]:找不到元素:#app'

isn't already defined in the template ?? 尚未在模板中定义?

thanks for feedback 感谢您的反馈

The el property is used to specify the element currently in the DOM to mount the Vue instance to. el属性用于指定DOM中当前要安装Vue实例的元素。

You can't specify that element within the Vue instance's template because it needs to mount somewhere on the DOM before it can render. 您无法在Vue实例的模板中指定该元素,因为它需要在DOM上的某个位置挂载后才能呈现。

You need to add an element with id #app to your html outside of your Vue instance and remove the id="app" from the div in its template. 您需要在Vue实例之外的HTML中添加ID为#app的元素,并从其模板的div中删除id="app"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM