CNode

jade问题,谁能帮我几天没解决,

问答
Llingke00发布于11 年前最后回复11 年前2 回复3849 浏览0 收藏

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)

J
jysperm#1·11 年前

我猜 extend 不能在 if .. else 里面

L
lingke00#2·11 年前
引用 jysperm我猜 extend 不能在 if .. else 里面

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

参与回复
登录后即可参与回复。登录