Home > Web Front-end > JS Tutorial > vue loads custom js file method

vue loads custom js file method

亚连
Release: 2018-05-30 17:03:51
Original
2426 people have browsed it

The editor below will share with you a method of loading custom js files in vue. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor and take a look.

When working on a project, you need to customize the pop-up box. I just wrote one myself.

Rendering

Problems encountered

How to load custom js File

vue-pluginThis must be seen. Then I just wrote it myself.

export default{
 install(Vue){
  var tpl;
  // 弹出框
  Vue.prototype.showAlter = (title,msg) =>{
   var alterTpl = Vue.extend({  // 1、创建构造器,定义好提示信息的模板
     template: &#39;<p id="bg">&#39;
       + &#39;<p class="jfalter">&#39;
       + &#39;<p class="jfalter-title" id="title">&#39;+ title +&#39;</p>&#39;
       + &#39;<p class="jfalter-msg" id="message">&#39;+ msg +&#39;</p>&#39;
       + &#39;<p class="jfalter-btn" id="sureBtn" v-on:click="hideAlter">确定</p>&#39;
       + &#39;</p></p>&#39;
   });
   tpl = new alterTpl().$mount().$el; // 2、创建实例,挂载到文档以后的地方
   document.body.appendChild(tpl); 
  }
  Vue.mixin({
   methods: {
   hideAlter: function () {
    document.body.removeChild(tpl);
   }
   }
  })
 }
}
Copy after login

Use

import jFAltre from &#39;../../assets/jfAletr.js&#39;;
import Vue from &#39;vue&#39;;
Vue.use(jFAltre);
Copy after login

this.showAlter(&#39;提示&#39;,&#39;服务器请求失败&#39;);
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Angular uses the operation event instruction ng-click to pass multiple parameters Example

Angular uses filters Uppercase/lowercase implements letter case conversion function example

Introduction to the problems and differences between apply and Math.max() functions in js

The above is the detailed content of vue loads custom js file method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template