W3C Validation and Vue's HTML binding syntax

不打扰是莪最后的温柔 提交于 2019-12-06 23:09:04

问题


When I validate my page with the W3C validator, I get this error with Vue's event and binding syntax:

Error: Attribute v-on:click not allowed on element div at this point.

Is there a way to fix this?


回答1:


They would ideally support the use of data-* attributes, e.g., data-v-on:click, but it seems they don’t.

See their issue Why not using HTML5 data-* attributes.

It seems that it was possible to overwrite the used prefix, but this option seems to have been removed.




回答2:


You can create a specific regular expression for ignoring errors caused through vue.js usage:

Attribute “((v-|:)[^”]+|@click)” not allowed.*

This regex can be used in different ways depending on how exactly you are validating your project. For example if you are using the CLI version of vnu.jar you can put it into a file and use the --filterfile LIST_OF_REGEXES.txt option. Or if you are setting up your own vnu.jar server then you can use -Dnu.validator.servlet.filterfile=LIST_OF_REGEXES.txt.

(Sadly, some wrappers such as html-validator/html-validator-cli for node and gulp-html apparently only support ignore strings and not regular expressions. Others such as grunt-html and html5validator so support it though.)



来源:https://stackoverflow.com/questions/39498365/w3c-validation-and-vues-html-binding-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!