jade问题,谁能帮我几天没解决,
发布于 9 年前 作者 lingke00 3126 次浏览 最后一次编辑是 8 年前 来自 问答

app.js --添加路由 /test

app.use('/test',routes)

routes/index.js 添加响应

router.get('/test', function(req,res) {
	res.locals.click = req.query.click;
	res.render('test');
})

views/test.jade

mixin content
	a(href = '/test?click=true') 测试
	p #{click}
if click
	+content
	p a
else
	extend layout
	block content
		+content
		p b

views/layout.jade 添加样式 background-color:red

doctype html
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body(style = "background-color:red")
    block content

测试:1.当输入localhost:3000/test时,click为undefined,输出 b 背景为红色 疑问:点击测试 ,click为true,应该输出 a true 没背景色才对,,为啥输出 b true 红色背景???

2 回复

我猜 extend 不能在 if … else 里面

@jysperm 应该是extend的问题,但不知道为啥?按说点测试时,路由重新加载,重新判断,和extend没啥关系~

回到顶部