A remote JS file is introduced inside the Vue component

Source: Internet
Author: User

This is done because a JS file needs to be introduced inside a component to locate it. If put in index.html, so each component will have this JS. So it needs to be introduced separately within the component.

The first operation of the DOM introduces JS:

default {  mounted () {    const s = document.createelement ('script');     'text/javascript';     ' Https://g.alicdn.com/dingding/dinglogin/0.0.2/ddLogin.js ' ;    Document.body.appendChild (s);  },}

The second method of use createElement :

Exportdefault{components: {'Dingtalk': {render (createelement) {returncreateelement ('Script', {attrs: {type:'Text/javascript', SRC:'Https://g.alicdn.com/dingding/dinglogin/0.0.2/ddLogin.js',            },          },        ); },    },  },}//use <dingtalk></dingtalk> to invoke in a page

The third encapsulates a component:

 export default   {components: {  " remote-js     return  createelement ( '  script  " , {attrs: {type:  " text/ JavaScript   ", src: this  .src}}); }, Props: {src: {type:string, Required:  true   

using:<remote-js src= "Your need for the JS file address" ></remote-js>

A remote JS file is introduced inside the Vue component

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.