我正在学习jade,以下是我的代码片段
extends layout
block content
h1= title
p Token is #{token.access_token}
script(type='text/javascript')
var tokenValue = JSON.parse(token);
sayhi(tokenValue);
在我的test.js里面我有
function sayhi(token) {
console.log(token);
}
如果我从sayhi发送文本 - 它完美无缺,但如果我发送tokenValue - 我会收到以下错误:
unexpected text ;
at Object.Lexer.fail (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/lexer.js:872:11)
at Object.Lexer.next (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/lexer.js:931:15)
at Object.Lexer.lookahead (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/lexer.js:113:46)
at Parser.lookahead (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/parser.js:102:23)
at Parser.peek (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/parser.js:79:17)
at Parser.tag (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/parser.js:751:22)
at Parser.parseTag (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/parser.js:737:17)
at Parser.parseExpr (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/parser.js:211:21)
at Parser.block (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/parser.js:707:25)
at Parser.tag (/home/shardul/WebstormProjects/trial/node_modules/jade/lib/parser.js:816:24)
答案 0 :(得分:2)
我在这里看到的一些问题。
token
目前是Jade中的变量,需要为JS编码,而不是解码。token
插入文本块。最终代码:
block content
h1= title
p Token is #{token.access_token}
script(type='text/javascript').
var tokenValue = #{JSON.stringify(token)};
sayhi(tokenValue);