Vue-loader: When I set an attribute be a string which include '<script>' tag, module build will fail.

Created on 8 Nov 2016  路  2Comments  路  Source: vuejs/vue-loader

HI!

I've some questions about vue-loader.

If I do that:

created(){
    this.test = `<script></script>`;
    // or just annotate
    // this.test = `<script></script>`;
}

It will throw an error:

Module build failed: Error: [vue-loader] Only one <script> or <template> tag is allowed inside a Vue component.

I konw that only one <script> tag is allowed inside a Vue component, but this is just a string and annotate.

I feel a bit puzzled, is this not allowed too?

Most helpful comment

This is how HTML is parsed. Doing the same in an HTML file will also cause an error.

You can escape the slash:

this.test = `<script><\/script>`

All 2 comments

This is how HTML is parsed. Doing the same in an HTML file will also cause an error.

You can escape the slash:

this.test = `<script><\/script>`

Hi @yyx990803 ,

I think this is still an issue.

You can escape the slash:

Yeah I can, but my linting rules (prettier) prevent me from escaping the forward slash as it is an 'unnecessary escape'. I don't think adding a rule to my configuration just for this issue is worth the effort, and I don't think it should be happening in the first place as it is such an unexpected behavior.

This is how HTML is parsed. Doing the same in an HTML file will also cause an error.

I was under the impression that the code inside <script> tags was treated as JavaScript (or TypeScript) and not html, I wouldn't think that it would be that much of an issue recognizing that a closing <script> tag exists in a string literal or comment, although I could be wrong.

Any reason as to why this shouldn't be fixed in regards to my thoughts above?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

frangio picture frangio  路  3Comments

fuyan-run picture fuyan-run  路  3Comments

flashios09 picture flashios09  路  3Comments

chrisvfritz picture chrisvfritz  路  4Comments

sdvcrx picture sdvcrx  路  3Comments