在我的项目symfony 4中,我想使用阿尔及利亚的地方来选择城市。
使用CDN <script src="https://cdn.jsdelivr.net/npm/places.js@1.17.0"></script>
效果很好。
我已经:
<script>
const fixedOptions = {
appId: '[id]',apiKey: '[key]',container: document.querySelector('#ordre_mission_lieu')
};
const reconfigurableOptions = {
language: 'fr',// Receives results in German
countries: ['fr'],// Search in the United States of America and in the Russian Federation
type: 'city',// Search only for cities names
aroundLatLngViaIP: false // disable the extra search/boost around the source IP
};
const placesInstance = places(fixedOptions).configure(reconfigurableOptions);
// dynamically reconfigure options
placesInstance.configure({
countries: ['fr'] // only search in the United States,the rest of the settings are unchanged: we're still searching for cities in German.
})
</script>
但是现在我想将其与NPM一起使用。
在文档中,他们显示了操作方法:https://community.algolia.com/places/documentation.html#using-npm
因此,我执行了这一行以获取软件包npm install places.js --save
而且由于我使用webpack-encore来管理我的资产。在我的app.js文件中,我这样做:
const places = require("places.js");
然后我删除了模板中的CDN链接。
然后,我毫无问题地编译了资产,然后重新加载了页面。但是没有考虑到阿尔戈利亚。在控制台中,出现此错误:
未捕获的ReferenceError:未定义场所 在新的:481
在const placesInstance = places(fixedOptions).configure(reconfigurableOptions);
那是什么问题?但是我已经在我的app.js中声明了我的places
变量可以使用它