Home > Web Front-end > JS Tutorial > body text

Summary of VUE key issues

亚连
Release: 2018-05-29 15:14:20
Original
2309 people have browsed it

This article summarizes the important and difficult points of VUE, and shares the code in detail. Friends who are interested can learn from it.

1. Three mounting methods for components

Automatic mounting

var app3 = new Vue({
 el: '#app-3',
 data: {
 seen: true
 }
})
Copy after login

Manual mounting

// 可以实现延迟按需挂载
<p id="app"> {{name}} </p> 
<button onclick="test()">挂载</button> 
<script> 
 var obj= {name: &#39;张三&#39;} 
 var vm = new Vue({ 
 data: obj
 }) 
 function test() { 
 vm.$mount("#app"); 
 }
Copy after login
// Vue.extend()创建没有挂载的的子类,可以使用该子累创建多个实例
var app= Vue.extend({ 
 template: &#39;<p>{{message}}</p>&#39;, 
 data: function () { 
 return { 
  message: &#39;message&#39;
  } 
 } 
 }) 
 new app().$mount(&#39;#app&#39;) // 创建 app实例,并挂载到一个元素上
Copy after login

2 , The way of routing parameters

<p>
  <!-- query要用path来引入,params要用name来引入,故不能写为 :to="{path:&#39;/login&#39;,params: {isLogin: true}} -->
  <!-- 跳转路由时用this.$router: this.$router.push({name:"login",params:{isLogin:true}});this.$router.push({path: &#39;/login&#39;, query: {isLogin : true}}); -->
  <!-- 接收参数时用this.$route: this.$route.query.isLogin 和 this.$route.params.isLogin; -->
  <router-link :to="{name:&#39;login&#39;,params: {isLogin: true}}">亲,请登录</router-link>
  <router-link :to="{name:&#39;login&#39;,params: {isLogin: false}}">免费注册</router-link>
 </p>
 <!-- 路由出口, 路由匹配到的组件将渲染在这里 -->
 <router-view></router-view>
Copy after login

3. Understanding render:h => h(App)

render:h=>h (App) is the arrow function writing method in ES6, which is equivalent to render:function(h){return h(App);}.

1. This in the arrow function points outside the function that wraps this. on the object.

2.h is the alias of creatElement, the general management of the vue ecosystem

3.template:'', components:{App} used in conjunction with render alone :h=>h(App) will achieve the same effect

The former recognizes the