我有一個名為 updateUI 的工廠函式,我將其匯入 index.js。匯入時,會識別 updateUI 的實體,但是在嘗試呼叫 updateUI 的方法時出現錯誤。
將所有代碼放入 index.js 可以消除錯誤,但仍然讓我摸不著頭腦。似乎只有在匯入時才會出現問題。為什么方法沒有被識別?
index.js
import '../../dist/output.css';
import { updateUI } from './display.js';
const test = updateUI('Daly City');
test.setBackground();
顯示.js
import { getWeather } from './apiCall';
const updateUI = async(location) => {
const res = await getWeather(location, process.env.apiKEY);
function updateCity() {
const city = document.querySelector('#location');
city.innerHTML = res.name;
};
function updateCurrentTemp() {
const currentTemp = document.querySelector('#current-temp');
const farenheit = Math.round((9/5)*(res.main.temp - 273) 32);
currentTemp.innerHTML = farenheit;
};
function updateConditions() {
const condition = document.querySelector('#weather');
condition.innerHTML = res.weather[0].description;
};
function setBackground() {
const date = new Date();
let time = date.getTime();
console.log(time);
};
return { updateCity, updateCurrentTemp, updateConditions, setBackground }
};
export { updateUI };
uj5u.com熱心網友回復:
@code 在評論中回答了問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/411429.html
標籤:
上一篇:HerokuNode.jsDiscord.js部署失敗
下一篇:從Webpack包中排除模塊
