如何在vue.js2中绑定DOM以在javaScript工厂函数中生成tweet?

如何在vue.js2中绑定DOM以在javaScript工厂函数中生成tweet?,javascript,dom,twitter,vue.js,vuejs2,Javascript,Dom,Twitter,Vue.js,Vuejs2,如何在vue.js2中绑定Document.getElementById。我正在使用带有javaScript工厂函数的嵌入tweet。如果我只在.html文件中使用DOM并在vue文件中生成tweet,那么它可以正常工作,但如果两者都在.vue文件中,则不工作。我需要在.vue文件中使用DOM,并将其与工厂函数绑定 我试过ref和v-el,但没有成功 <template> <div class="row" id="home"> <h3 v-if="m

如何在vue.js2中绑定Document.getElementById。我正在使用带有javaScript工厂函数的嵌入tweet。如果我只在.html文件中使用DOM并在vue文件中生成tweet,那么它可以正常工作,但如果两者都在.vue文件中,则不工作。我需要在.vue文件中使用DOM,并将其与工厂函数绑定

我试过ref和v-el,但没有成功

<template>
  <div class="row" id="home">
      <h3 v-if="msg"><span class="label label-warning">{{msg}}</span></h3>
    </div>
    <!--<div v-for="tweet in tweetHtml">
      <div v-html="tweet"></div>
    </div>-->
  </div>
  <div id="container" ></div> <!-- generated tweet from fun should bind here -->
</template>

<script>
import appService from '../service'
import bus from '../service/bus'

export default {
  data() {
    return {
      searchedTopic: '',
      user_id: '',
      tweets: {},
      tweetHtml: []
    }
  },
  created() {
    // generate tweet with javaScript factory fun <<---=-=-=-=
    twttr.widgets.createTweet('20',
    document.getElementById('container'),  // <<-- what to do to bind container with vue file's div.
    {
      theme: 'light'
    })
    .then( function( el ) {
      console.log('Tweet added.');
    });
  },
  methods: {

  }
}
</script>

{{msg}}
从“../service”导入appService
从“../service/bus”导入总线
导出默认值{
数据(){
返回{
搜索主题:“”,
用户id:“”,
推特:{},
tweetHtml:[]
}
},
创建(){

//使用javaScript factory fun生成tweet如果您刚刚获得DOM节点,那么使用ref就可以了


twttr?这是什么?

不确定您想做什么,但您可以使用
$refs
,类似这样的
,然后像这样访问它
this.$refs.container
-注意
这个
到twttr对象中的
不会被Vue实例引用,所以在
var self=this
之前声明并使用
self.$refs.container
@BelminBedak我已经尝试过了,但是id没有起作用。我已经提到了。在你的评论之后,我又尝试了一次。我已经写过的答案是什么?我接受你的观点。我在发布时没有看到它,sorry@strive.chen看这个@DhruvGoradiya谢谢。