gpt4 book ai didi

javascript - ES6 功能不可用

转载 作者:行者123 更新时间:2023-11-30 09:10:24 24 4
gpt4 key购买 nike

我收到以下错误:

namesearch.js:5 Uncaught ReferenceError: autoComplete is not defined at Namesearch (namesearch.js:5)

./index.js

import autoComplete from '@tarekraafat/autocomplete.js/dist/js/autoComplete';
import Namesearch from './components/namesearch';

document.addEventListener('DOMContentLoaded', function () {
console.log(' DOM is now safely manipulable.');
Namesearch();
});

./components/namesearch.js

export default function () {

console.log("autoComplete function");

const autoCompletejs = new autoComplete({
data: {
src: async () => {
...

如果我将逻辑直接放入 index.js 一切正常,但我想做更模块化的事情。我在这里错过了什么?

最佳答案

您需要在 namesearch.js 中导入 autoComplete。

import autoComplete from '@tarekraafat/autocomplete.js/dist/js/autoComplete';

export default function () {

console.log("autoComplete function");

const autoCompletejs = new autoComplete({
data: {
src: async () => {
...

关于javascript - ES6 功能不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59564030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com