vue拼接字符串包括时报错误提示Unterminated template literal

vue拼接字符串包括script标签时报错误提示Unterminated template literal解决方法加反斜杠就可以,在script结束标签里边加反斜杠<\/script>

`<a href="${this.formData.url}" target="_balnk" >
   <img src="${image_url}" id="img" style="width:100%;height:100%" onclick="click(${this.formData.id})"/>
    <script>
            function click(id) {
                var xhr = new XMLHttpRequest();
                var url = 'https://api.com/index';
                xhr.onload = function() {
                    if (xhr.readyState === 4) {
                        if (xhr.status === 200) {
                        } else {
                            console.error(xhr.statusText);
                        }
                    }
                };
                xhr.open('POST', url, true);
                xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
                xhr.timeout = 10 * 1000;
                xhr.send(JSON.stringify({'id': id}));
            }
      <\/script>  
 </a>`
Logo

前往低代码交流专区

更多推荐