Vue How to Import external JS files (ES6)

Source: Internet
Author: User

Perhaps everyone is used to use the es5 of the writing like to directly use the "Script" tag into the JS file, but it is a pity, the wording. In Es6, or in the Vue environment.


What's the real writing?


First of all. We want to transform the external JS file that we want to enter, and change it to the following format. mainly red block internal code, we need to "throw" our module, so that people can get to

Code:

[HTML]View PlainCopy
    1. function Realconsole () {
    2. Alert ("Hello.thanks use Me");
    3. }
    4. Export {
    5. Realconsole
    6. }


Secondly, to our host, we need to import, imitate other documents, the wording is this:

Code:

[HTML]View PlainCopy
  1. <template>
  2. <div class="teslist">
  3. <button @click="METHODS1"> Show console</button>
  4. </div>
  5. </Template>
  6. <script src=". /.. /lib/myconsole.js "></script>
  7. <script>
  8. Import {Realconsole} from '. /.. /lib/myconsole.js '
  9. Export Default {
  10. methods:{
  11. Methods1:function () {
  12. Realconsole ();
  13. }
  14. }}
  15. </Script>
  16. <style>
  17. . teslist {
  18. }
  19. </style>


Pay attention to the Red fork part, that is our es5, green is correct

Followed by

Two. Direct introduction of the cannot be downloaded with NPM

Introduction of SWIPER.CSS and Swiper.js files in View.vue

The code in View.vue is written like this:

1234567891011121314151617181920212223242526272829 <template>...</template><script>importswiper from ‘./swiper.js‘importcommon from ‘../common.vue‘exportdefault {    data(){        return{        }    },    mounted:function(){        this.swippertab();    },    methods:{        swippertab(){             varswiper = new Swiper(‘.swiper-container‘, {                pagination: ‘.swiper-pagination‘,                slidesPerView: 3,                paginationClickable: true,                spaceBetween: 30            });        },    }</script><style scoped>@import‘./swiper.css‘;</style>

Note that it is necessary to change the code in the Swiper.js, the last side of the change to export the swiper with exports, and the code of the original AMD format of the export needs to comment out

Vue How to Import external JS files (ES6)

Related Article

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.