Vue知识随笔

全局参数

1.global.js 先定义常量参数

const BASE_URL = 'http://xxxx.xxxx.com/api';
export default {
BASE_URL
}

2.main.js 在main.js里面创建全局参数

import global from './../static/config/global';
Vue.prototype.GLOBAL = global;

3.vue页面内

this.GLOBAL.BASE_URL

$refs(vue $refs的基本用法)##



<button @click="add">添加

this.$refs.input1.value ="22"; //this.$refs.input1减少获取dom节点的消耗

一般来讲,获取DOM元素,需document.querySelector(".input1")获取这个dom节点,然后在获取input1的值。
但是用ref绑定之后,我们就不需要在获取dom节点了,直接在上面的input上绑定input1,然后$refs里面调用就行。
然后在javascript里面这样调用:this.$refs.input1 这样就可以减少获取dom节点的消耗了

获取路由内参数

{
path: '/proDetail/:id',
name: 'ProDetail',
component: ProDetail
}

this.productId = this.$route.params.id;

获取链接中参数

http://m.xxxx.com/#/latestPlan?chn=app

this.$route.query.chn

posted @ 2017-12-15 11:17  CalronLoveRonnie  阅读(159)  评论(0)    收藏  举报
AmazingCounters.com