尝试了两种导出方式,对应两种引用方式。
1. 导出方式一:
被引用脚本路径:my-app > src > renderer > module > checkObject.js
, 代码如下
'use strict'
let CheckObject = function () {}
CheckObject.prototype = {
checkName: function (name) {
console.log(name);
return this
},
checkEmail: function (email) {
console.log(email);
return this
},
checkPassword: function (pwd) {
console.log(pwd);
return this
}
}
module.exports = CheckObject
引用脚本路径:my-app > src > renderer > components > Home > Home.vue
, 代码如下
<script>
let CheckObject = require("../../module/checkObject")
let a = new CheckObject()
a.checkEmail("xxx@xx.com").checkName("zs").checkPassword("123456")
</script>
打印:
2. 导出方式二:
被引用脚本路径:my-app > src > renderer > module > checkObjectES6.js
, 代码如下
'use strict'
export let CheckObject = function () {}
CheckObject.prototype = {
checkName: function (name) {
console.log(name);
console.log("===",this);
return this
},
checkEmail: function (email) {
console.log(email);
console.log("---",this);
return this
},
checkPassword: function (pwd) {
console.log(pwd);
console.log("-=-", this);
return this
}
}
引用脚本路径:my-app > src > renderer > components > Home > Home.vue
, 代码如下
<script>
import { CheckObject } from "../../module/checkObjectES6"
let a = new CheckObject()
a.checkEmail("xxx@xx.com").checkName("zs").checkPassword("123456")
</script>
打印: