• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

vue 搞代码 4年前 (2022-01-08) 51次浏览 已收录 0个评论

这篇文章主要介绍了vue组件暴露和.js文件暴露接口操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

1、将同一类型的组件放在一个文件夹下

2、在此文件夹下创建一个index.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<em>本文来源gao.dai.ma.com搞@代*码(网$</em>, 'StudentInfo':studentInfo } }

1、将.js放在同一个文件夹下

2、同样一定要有一个index.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文件暴露接口操作的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:vue组件暴露和.js文件暴露接口操作

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址