久久久久久AV无码免费看大片,亚洲一区精品人人爽人人躁,国产成人片无码免费爱线观看,亚洲AV成人无码精品网站,为什么晚上搞的时候要盖被子

vue定義全局變量和全局方法

時(shí)間:2019-09-08 09:32:33 類型:vue
字號:    

一、全局引入文件

1、先定義共用組件 common.vue

    

<script type="text/javascript">
    // 定義一些公共的屬性和方法
    const baseUrl = 'http://www.y46k9ti.cn/'
    function getMyname() {
        console.log("南昌雅騰")
    }
    // 暴露出這些屬性和方法
    export default {
        baseUrl,
        getMyname
    }
</script>
2.  直接在單個(gè).vue文件中使用

<script lang="ts">
import { Component, Vue ,Watch } from 'vue-property-decorator';
import Nav from './Nav.vue';
import globals from '../components/common.vue'
@Component({
  components: {
    Nav,
  },
})

export default class Home extends Vue {
	 title:string = "南昌雅騰首頁";
	 content:string="";
	 classid:number=0;
	 mounted(){
	 	   console.log(globals.baseUrl);
           $("title").html(this.title);
      }
     created(){
     	
     }
}
</script>

二、main.js/main.tsyywr中引入全局變量和方法

     1. 定義common.vue同上

    2. main.ts文件中引入并賦值

import globals from './components/common'
Vue.prototype.globals = globals
  3. 直接在.vue文件中引用
export default class Home extends Vue {
	 title:string = "南昌雅騰首頁";
	 content:string="";
	 classid:number=0;
	 mounted(){
	 	   console.log(this.globals.baseUrl);
           $("title").html(this.title);
      }
     created(){
     	
     }
}