Vuejs javascript文件中的令牌无效或意外
在我的vue组件js代码中,我收到了以下错误: 未捕获的语法错误:无效或意外标记 这是我的代码:Vuejs javascript文件中的令牌无效或意外,javascript,vue.js,vue-component,Javascript,Vue.js,Vue Component,在我的vue组件js代码中,我收到了以下错误: 未捕获的语法错误:无效或意外标记 这是我的代码: Vue.component('pickpoint-info', { template : '<table>\ // in this line I get the error <tbody>\ <tr v-for="item in items" v-on:click="sel
Vue.component('pickpoint-info', {
template : '<table>\ // in this line I get the error
<tbody>\
<tr v-for="item in items" v-on:click="selectPickPoint(this)">\
<td width="50" align="center"><input name="pickpointid" type="radio" value="{{ item.customer_id }}"></td>\
<td width="300">\
<b>{{ item.name }}</b> <i style="font-size:9px;">#{{ item.customer_id }}</i>\
<br>\
{{ item.address }}\
<br>\
{{ item.postal_code }}\
<a href="{{ item.map_link }}" target="_blank" style="font-size:10px;">(ver en el mapa</a>)\
</td>\
</tr>\
</tbody>\
</table>\
',
Vue.component('pickpoint-info'{
模板:'\//在这一行我得到了错误
\
\
\
\
{{item.name}}{{item.customer\u id}}\
\
{{item.address}}}\
\
{{item.posal_code}\
)\
\
\
\
\
',
此代码有什么问题?尽量避免使用字符串作为模板,而是使用
HTML5
模板标记并引用它:
<template id="my-template">
<table> in this line I get the error
<tbody>
<tr v-for="item in items" v-on:click="selectPickPoint(this)">
<td width="50" align="center">
<input name="pickpointid" type="radio" value="{{ item.customer_id }}">
</td>
<td width="300">
<b>{{ item.name }}</b> <i style="font-size:9px;">#{{ item.customer_id }}</i>
<br> {{ item.address }}
<br> {{ item.postal_code }}
<a href="{{ item.map_link }}" target="_blank" style="font-size:10px;">(ver en el mapa</a>)
</td>
</tr>
</tbody>
</table>
</template>
如果要使用字符串,请检查行尾并确保反斜杠后没有空格,我认为您的错误在于这两行:
{{ item.address }}\
<br>\
{{item.address}}\
\
这两种方法的末尾都有需要删除的
空格。您必须写反勾号,而不是简单的引号。要写反勾号,您可以查看此链接
在我的情况下(使用qwertz键盘),它是“Alt Gr”+“7”(可能需要按两次).或者如果他想使用字符串,ES2015中有专门的模板字符串。但是我同意你的意见-关于使用HTML5template
标记。是的,尽管它们需要编译,甚至babel
默认情况下也不包括模板文本
转换,所以如果你这样做,你也可以这样做使用一个更干净的单页组件。嗯,但这是一个组件,我在这个视图中不使用html。在任何html文件中,我想使用标记并呈现组件。你可以将它们分离到一个视图文件中,并将其包含在html中。使用字符串作为复杂模板的问题正是你所遇到的例如,尝试查找缺少串联或转义字符的位置。您还应该查看它们使您的生活更加轻松。我已更新了我的答案,以向您说明我认为字符串模板的问题所在。
{{ item.address }}\
<br>\