简体   繁体   English

在附加元素内渲染 Vue

[英]Render Vue inside appended element

I am making some chrome extension and it worked in jquery but because of some reactivity, I needed to switch to Vuejs.我正在制作一些 chrome 扩展,它在 jquery 中工作,但由于一些反应性,我需要切换到 Vuejs。

Now if I bind Vue onto some random div, content from that div will be removed.现在,如果我将 Vue 绑定到某个随机 div 上,该 div 中的内容将被删除。

So I tried to append some element and then use that one, but seems like Vue can't find it.所以我尝试附加一些元素然后使用那个元素,但似乎 Vue 找不到它。

  let el = document.createElement('div');
  el.style.cssText = 'position:fixed;top:0;left:0;';
  el.id = '#random12345';
  document.body.appendChild(el);
  setTimeout(function () {
    const app = new Vue({
      el: "#random12345",
      data: {},
      render: h => h('some-component')
    });
  }, 3000);

For this I keep getting an error: [Vue warn]: Cannot find element: #random12345为此,我不断收到错误消息: [Vue 警告]:找不到元素:#random12345

#random12345 selector means that it looks for an element with id attribute equal to random12345 . #random12345选择器意味着它查找id属性等于random12345的元素。

It should be:它应该是:

el.id = 'random12345';

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

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