sfjlkd
sfjlkd
  • 发布:2018-12-18 18:55
  • 更新:2020-06-28 11:38
  • 阅读:47899

uniapp怎么引入外部js

分类:uni-app

我要使用 aliyun-oss-sdk.min.js 怎么引入?

我在 App.vue 文件下 import OSS from 'common/aliyun-oss-sdk.min.js' 不起作用

在自己写的js 文件里面 import OSS from 'common/aliyun-oss-sdk.min.js' 会保存

在要使用的页面(如a.vue中)引入 import OSS from 'common/aliyun-oss-sdk.min.js' 也不起作用

2018-12-18 18:55 负责人:无 分享
已邀请:
sfjlkd

sfjlkd (作者) - 我的1

阿里云的,整理后1万多行代码 ....囧....

5***@qq.com

5***@qq.com

在js 最后 加上: export{ ‘属性’,‘对象’,函数 } 需要用到的地方 import from ----- 试一下,有没有效果。或者直接用 npm安装 :如果缺少package.json 就百度一个,
或者下面这个你可以试一下:
{
"name": "uniapp",
"version": "2.0.0",
"private": true,
"scripts": {
"lint": "eslint --color --ext .js,.vue src",
"lint-fix": "eslint --color --fix --ext .js,.vue src",
"dev": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch",
"build": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build",
"dev-app": "cross-env NODE_ENV=development UNI_PLATFORM=app-plus vue-cli-service uni-build --watch",
"dev-h5": "cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve",
"dev-alipay": "cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch",
"dev-baidu": "cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch",
"dev-toutiao": "cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch",
"build-app": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
"build-h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build",
"build-alipay": "cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build",
"build-baidu": "cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build",
"build-toutiao": "cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build",
"info": "node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js"
},
"dependencies": {
"@dcloudio/uni-app-plus": "",
"@dcloudio/uni-h5": "
",
"@dcloudio/uni-mp-alipay": "",
"@dcloudio/uni-mp-baidu": "
",
"@dcloudio/uni-mp-toutiao": "",
"@dcloudio/uni-mp-weixin": "
",
"cli": "^1.0.1",
"flyio": "^0.6.2",
"hydrogen-js-sdk": "^2.2.4",
"node-sass": "^4.12.0",
"regenerator-runtime": "^0.12.1",
"sass-loader": "^7.3.1",
"vue": "^2.6.10",
"vuex": "^3.0.1"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.4.0",
"@dcloudio/uni-cli-shared": "",
"@dcloudio/uni-template-compiler": "
",
"@dcloudio/vue-cli-plugin-hbuilderx": "latest",
"@dcloudio/vue-cli-plugin-uni": "0.9.34",
"@dcloudio/webpack-uni-mp-loader": "",
"@dcloudio/webpack-uni-pages-loader": "
",
"@types/html5plus": "",
"@types/uni-app": "
",
"@vue/cli-plugin-babel": "3.5.1",
"@vue/cli-service": "^3.10.0",
"@vue/eslint-config-prettier": "^4.0.1",
"@vue/eslint-config-standard": "^4.0.0",
"babel-eslint": "^8.2.2",
"babel-plugin-import": "^1.11.0",
"crypto-js": "^3.1.9-1",
"eslint": "^4.15.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-standard": "^11.0.0",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-vue": "^4.7.1",
"less": "^3.9.0",
"less-loader": "^4.1.0",
"postcss-comment": "^2.0.0",
"shelljs": "^0.8.3",
"vue-template-compiler": "^2.6.10",
"weex-vue-loader": "^0.7.0",
"yargs": "^13.2.2"
},
"browserslist": [
"last 3 versions",
"Android >= 4.4",
"ios >= 8"
],
"uni-app": {
"scripts": {}
}
}

DCloud_UNI_GSQ

DCloud_UNI_GSQ

首先保证你的aliyun-oss-sdk.min.js是模块化的,主流模块都支持。
es6 模块 export default 导出

 import xxx from './common/xxx.js'

es6 模块 export 导出

 import {xxx} from './common/xxx.js'

commonjs、adm、cmd 模块

 var xxx = require('./common/xxx.js')
  • zzk

    bmob引入后小程序里面会报错(网页正常),关掉转es6可以用,但是可能会有兼容问题

    2018-12-19 10:04

sfjlkd

sfjlkd (作者) - 我的1

http://gosspublic.alicdn.com/aliyun-oss-sdk-4.4.4.min.js

这种js好像是没有模块化的,是阿里云的OSS JavaScript SDK

这个有没什么办法

7***@qq.com

7***@qq.com

请问您解决问题了吗?怎么整的?

  • 鱼丸粗面丨

    随便改成commonjs、adm、cmd 模块中的一种。

    2019-04-28 10:42

  • hafanYao

    回复 鱼丸粗面丨: 能指点一下吗仁兄?有重谢~

    2019-10-17 19:15

  • hafanYao

    方便的花联系我,必定重谢~qq:593908491

    2019-10-17 19:34

y***@126.com

y***@126.com - 码农

import xxx from './common/xxx.js' 这个样子的行不通。

符号

符号 - 做自己,稳步向前!!

您好,解决了嘛,怎么引入外部js

  • y***@126.com

    解决了

    2019-10-08 09:15

  • 5***@qq.com

    回复 y***@126.com: 您好,可以说一下怎么解决吗

    2019-10-08 16:52

  • hafanYao

    回复 y***@126.com: 能指点一下吗仁兄?有重谢~

    2019-10-17 19:15

  • hafanYao

    方便的花联系我,必定重谢~qq:593908491

    2019-10-17 19:34

  • 1***@qq.com

    回复 hafanYao: 解决没 哥

    2020-07-08 10:29

  • [已删除]

    回复 hafanYao: 解决了吗

    2020-08-03 10:54

  • l***@sina.cn

    回复 y***@126.com: 这就很奇怪了,解决了怎么不说下解决方案呢。。。人家问解决了吗,肯定是想要方案,你就回个解决了。。。方案就不舍得拿出来吗?

    2020-10-30 15:06

1***@qq.com

1***@qq.com

https://ask.dcloud.net.cn/article/35657
这样也可以

该问题目前已经被锁定, 无法添加新回复