问题
I'm new to webpack and this module bundler stuff and I'm currently just experimenting around what's possible and what isn't.
Here, I'm trying the following:
//appECommerce.js
import eCommerceLogic from './lib/eCommerceLogic.js'
//eCommerceLogic.js
import name from './eCommerceJSExportTests.js';
module.exports = {
productnamesOnclick: function(){
$("#AJAXproductnames").on("click",function(){
getProductnameElements()
})
},
productNamesGetter: function(){
async function getProductnameElements(){
let productNameElements = document.getElementsByClassName('customProductCardName')
console.log("result is ", productNameElements)
let test = await name.commonAJAXCall()
console.log(test)
}
}
}
//eCommerceJSExportTests.js
module.exports = {
commonAJAXCall: function() {
//return "helloExport"
return $.get('https://jsonplaceholder.typicode.com/todos/1', {
}).then((response) => {
response = JSON.stringify(response)
console.log(response)
console.log("AJAX happened")
return response
})
}
}
So basically, I just want to know why I get this error (see title)^^ Furthermore though, I'd also like to know three specific things:
1) Is it possible to have module B import from module C and then export to module A, where the content of module B's import eventually consists of both its "own" code and the code imported from module C, since module B makes use of the imported properties and methods from module C there?
2) In code which is exported like shown above, is it actually possible to have method A containing a call to method B?
3) Can code which attaches event listeners to the DOM even be exported?
来源:https://stackoverflow.com/questions/57425344/typeerror-exports-is-read-only-when-exporting-a-module-with-method-calling