问题
I am doing the Wes-bos Learn node course.I am on the part of saving stores and using mixins. When I write mixins and run my app it gives this error.
Error: C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\views\mixins\_storeForm.pug:1:1
> 1| mixin storeForm(store = {})
-------^
2| form(action="/add" method="POST" enctype = "multipart/form-data" class="card")
3| label(for="name") name
4| input(type="text" name="name")
Mixin storeForm declared without body
at makeError (C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\node_modules\pug-error\index.js:32:13)
at Parser.error (C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\node_modules\pug-parser\index.js:53:15)
at Parser.parseMixin (C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\node_modules\pug-parser\index.js:871:12)
at Parser.parseExpr (C:\Users\ATUL\Downloads\Learn-Node-master\Learn-Node-master\starter-files\node_modules\pug-parser\index.js:204:21)
This is the file in Mixins (_storeForm.pug)
mixin storeForm(store = {})
form(action="/add" method="POST" enctype = "multipart/form-data" class="card")
label(for="name") name
input(type="text" name="name")
This is the file in views folder
extends layout
include mixins/_storeForm
block content
.inner
h2= title
+storeForm({name:'dkjd'})
I am new to nodejs/pug/express. What is wrong with this code. This code in the given video works fine but not on my desktop.
回答1:
Inside your mixin storeForm
, you need to indent form
and its children once more. Like so:
mixin storeForm(store = {})
form(action="/add" method="POST" enctype = "multipart/form-data" class="card")
label(for="name") name
input(type="text" name="name")
来源:https://stackoverflow.com/questions/46528783/mixin-declared-without-body