Vite(在Laravel)和Alpinejs不起作用
根据迁移说明,我从Laravel Mix转移到Laravel Vite。除高山外,一切都在编译和工作。在我的控制台中,我会得到以下内容。
参考:找不到变量:alpine`
Resources/app.js
import Alpine from 'alpinejs';
window.Alpine = Alpine;
// Stores need to be defined before Alpine.start()
import './alpine-stores/modal';
Alpine.start();
Alpine Stores/Modal
Alpine.store('modal', {
active: false,
id: null,
open(id) {
this.active = true
this.id = id
document.body.classList.add('overflow-hidden')
window.dispatchEvent(new CustomEvent('modalopened'))
},
close() {
this.active = false
this.id = null
document.body.classList.remove('overflow-hidden')
window.dispatchEvent(new CustomEvent('modalclosed'))
}
})
I've moved from Laravel Mix to Laravel Vite per the migration instructions. Everything is compiling and working, except for Alpine. In my console I get the following.
ReferenceError: Can't find variable: Alpine`
resources/app.js
import Alpine from 'alpinejs';
window.Alpine = Alpine;
// Stores need to be defined before Alpine.start()
import './alpine-stores/modal';
Alpine.start();
alpine-stores/modal
Alpine.store('modal', {
active: false,
id: null,
open(id) {
this.active = true
this.id = id
document.body.classList.add('overflow-hidden')
window.dispatchEvent(new CustomEvent('modalopened'))
},
close() {
this.active = false
this.id = null
document.body.classList.remove('overflow-hidden')
window.dispatchEvent(new CustomEvent('modalclosed'))
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于VITE,我们不能使用要求语句。因此,在分离数据和存储的同时更加复杂。我无法在Alpinejs网站上找到任何官方信息。我还经历了相同的问题,并以这种方式解决了这种类型的问题。
Alpine-data
资源/app.js
高山商店不要使用箭头功能
Due to vite we cannot use require statement. So while separating file for data and store is more complicated. I cannot found any official information on alpinejs website. I also pass through same problem and solve this type of problem in this way.
alpine-data
resources/app.js
For alpine store don't use arrow function