简体   繁体   English

vue事件不起作用-nuxtjs静态网站

[英]vue event not working - nuxtjs static website

I have set up mouseover and mouseleave event on img tag: 我已经在img标签上设置了mouseover和mouseleave事件:

<img @mouseover="large" @mouseleave="resize" src="/img/intro-bologna-1.jpg" alt="Bologna gallery" class="gallery__img gallery__img--1">

methods:{
        large(event){
            let siblings = this.findAllSiblings(event.target)
            siblings.forEach(sibling => sibling.style.transform = 'scale(.9)')
            event.target.style.transform = 'scale(1.2)'
        },
        resize(event){
            let siblings = this.findAllSiblings(event.target)
            siblings.forEach(sibling => sibling.style.transform = '')
            event.target.style.transform = ''
        },
        findAllSiblings(el){
            let parent = el.parentElement;
            let children = Array.from(parent.children);
            let siblings = children.filter(child => {
                return child !== el
            })
            return siblings
        }
    }

I dont understand why but when I run npm run generate and check the index.html file (I want to build a 100% static website) the hover effect doesn't work anymore (it works in dev enviroment) 我不明白为什么,但是当我运行npm run generate并检查index.html文件(我想建立一个100%静态网站)时,悬停效果不再起作用了(它在dev环境中起作用)

I've checked the source of the dist folder and I have an pages_index.a57c13c1cfd73bfe116e.js file where I can see the methods I wrote 我已经检查了dist文件夹的来源,并且有一个pages_index.a57c13c1cfd73bfe116e.js文件,在这里可以看到我编写的方法

How can I solve? 我该如何解决? Thanks 谢谢

I've tested your code and it works just fine . 我已经测试过您的代码, 并且效果很好

I believe that your script paths are wrong in the generated index.html as you probably don't run it from root of domain. 我相信您的脚本路径在生成的index.html中是错误的,因为您可能不是从domain的根目录运行它。 Your paths to assets like /_nuxt/ will be wrong. 您通往/_nuxt/类的资产的路径将是错误的。 You should be able to verify this by looking into the console, you will see lot of these not found files: 您应该能够通过查看控制台来验证这一点,您将看到许多未找到的文件:

/ _nuxt /某些路径仅在根域有效

In order to test your generated index.html just like this in browser, you might want to turn your /dist/ folder into a vhost using whatever environment you prefer. 为了像在浏览器中一样测试生成的index.html,您可能希望使用您喜欢的任何环境将/dist/文件夹转换为虚拟主机。 To test your code, i used laravel-valet and valet link in /dist/ folder to a sample domain, but you might just as well use Apache vhost, upload the code to testing webhosting or anything like that. 为了测试您的代码,我使用了/dist/文件夹中的laravel-valetvalet link到示例域,但是您可能同样会使用Apache vhost,将代码上传到测试虚拟主机或类似的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM