请问报错:Uncaught SyntaxError: Invalid or unexpected token

var vm = new Vue({
    el: '#app',
    data: {
        tabIndex: 0,
        isCarrier: false,
        carrierDispute: {
            infoId:"${mbInfo.infoId}",
            title:"${mbInfo.title}",
            brief:"${mbInfo.brief}",
            content:"${mbInfo.content}",
            item: [],
            addAttachmentList: [
                <#if mbInfo.addAttachmentList?exists>
                    <#list mbInfo.addAttachmentList as attachment>
                        ${attachment.id}
                        ${attachment.orderNo}
                        ${attachment.attachmentName}
                        ${attachment.attachmentUrl}
                    </#list>
                </#if>
            ]
        }
    },

这样输出,运行时在${attachment.id}就报错:Uncaught SyntaxError: Invalid or unexpected token

addAttachmentList: [
                        1300cedb0fc311e9ae5528e347618294
                        12fdc19a0fc311e9ae5528e347618294
                        7.png                           http://10.1.8.41:80/group1/M00/00/36/CgEIKVwuu82AIsuCAACbuTufRlw141.png
                        13049f6c0fc311e9ae5528e347618294
                        12fdc19a0fc311e9ae5528e347618294
                        8.png
                        http://10.1.8.41:80/group1/M00/00/36/CgEIKVwuu8-AQmYAAABlM71NEyI301.png
                        1305fefd0fc311e9ae5528e347618294
                        12fdc19a0fc311e9ae5528e347618294
                        9.png
                        http://10.1.8.41:80/group1/M00/00/36/CgEIKVwuu9GAGd3sAABlnVKB4kg072.png
            ]
阅读 6.4k
1 个回答
addAttachmentList: [
                        1300cedb0fc311e9ae5528e347618294
                        12fdc19a0fc311e9ae5528e347618294
                        7.png                           http://10.1.8.41:80/group1/M00/00/36/CgEIKVwuu82AIsuCAACbuTufRlw141.png
                        13049f6c0fc311e9ae5528e347618294
                        12fdc19a0fc311e9ae5528e347618294
                        8.png
                        http://10.1.8.41:80/group1/M00/00/36/CgEIKVwuu8-AQmYAAABlM71NEyI301.png
                        1305fefd0fc311e9ae5528e347618294
                        12fdc19a0fc311e9ae5528e347618294
                        9.png
                        http://10.1.8.41:80/group1/M00/00/36/CgEIKVwuu9GAGd3sAABlnVKB4kg072.png
            ]

这个不是合法的 JS 代码,如果只是想把字符串赋值到 JS 数组中,就加上引号和逗号呀

addAttachmentList: [
    <#if mbInfo.addAttachmentList?exists>
        <#list mbInfo.addAttachmentList as attachment>
            "${attachment.id}",
            "${attachment.orderNo}",
            "${attachment.attachmentName}",
            "${attachment.attachmentUrl}",
        </#list>
    </#if>
]

上面只是示例代码,需要实现什么还要自己调整

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题