您的位置:首頁技術文章
文章詳情頁

vue組件暴露和.js文件暴露接口操作

瀏覽:94日期:2022-12-10 11:48:37

1、將同一類型的組件放在一個文件夾下

2、在此文件夾下創建一個index.js

vue組件暴露和.js文件暴露接口操作

3、在index.js中導入組件,并把他們暴露出去

1、寫法一

import studentCourse1 from ’./studentCourse.vue’ import studentInfo1 from ’./studentInfo.vue’ export var studentCourse=studentCourse1 export var studentInfo=studentInfo1

2、寫法二

export var studentCourse=()=>import(’./studentCourse.vue’) export var studentInfo=()=>import(’./studentInfo.vue’) //export var studentInfo=()=>{ return import(’./studentInfo.vue’) }

4、最后在.vue文件中使用組件

此處你只需引入index.js所在文件夾就行啦

import {studentCourse,studentInfo} from ’./components/stuCom’ export default{ components:{ ’StudentCourse’:studentCourse, ’StudentInfo’:studentInfo } }

1、將.js放在同一個文件夾下

2、同樣一定要有一個index.js文件

vue組件暴露和.js文件暴露接口操作

3、 index.js文件內容如下

import auth from ’./auth.js’ import error from ’./error-log.js’ export default{ auth, error }

4、在main.js中

import utils from ’./utils’

Vue.use(utils.auth,{params})

補充知識:vue項目中將方法名暴露給APP端調用

只需要將methods中的方法賦值到window對象即可

created() { window.getParams = this.getParams}, methods: { getParams(params) { this.id = params.id // ... },}

也可以賦值給window對象中的某個對象

以上這篇vue組件暴露和.js文件暴露接口操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
国产综合久久一区二区三区