Uncaught SyntaxError: Illegal return statement (return 语句只能出现在函数体中。)

Uncaught SyntaxError: Illegal return statement (return 语句只能出现在函数体中。)

起因

之前写a标记一直写成

<a href='javascript: return false;'>test</a>

结果每次点击的时候都爆红,看着别扭,之前还没太发现~ 然后就加了个闭包~ 舒爽了~

解决代码

noteArr.forEach(item => {
            const template = `
            <div><a href='javascript: (function () { return false; })()' onClick="(function () {
              console.info('window.$router.history.current.path', window.$router.history.current.path)
if ('${item.jumpUrl}' == window.$router.history.current.path) {
  console.info('当前相同不跳转') 
} else {
window.$router.push({ 
  path: '${item.jumpUrl}',
  query: {
    flushDate: new Date().getTime()
  }
  });
}
            })()">${item.title}(${item.number})</a></div>
            `
            html += template
          })
posted @ 2024-04-02 15:40  彭成刚  阅读(74)  评论(0编辑  收藏  举报