如何在pug脚本中访问传递给pug的变量?

问题描述 投票:1回答:1

实际上,我现在正在从事Web开发,这是我正在从事的第一个工作。我正在尝试从主应用程序传递变量,例如

app.get('/',(req,res)=>{
    getdata().then(record=>{
        res.render("index",{title:'Login',users:record})
    })        
})

然后在我的index.pug文件中,除了我的脚本之外,其他任何地方都可以访问变量,>

form()
          input(type="text", class='normal',id='uname', placeholder = 'Username')
          input(type="password", class='normal',id='password', placeholder='Password')
          input(type="submit", class='submit',value="Login",onclick="checkaccount(users)")
script.
    function checkaccount(users){
      let user=document.getElementById('uname').value
      let password = document.getElementById('password').value
      console.log(users)
    } 

该代码不会执行,因为用户变量未定义。**用户变量是格式为array(a,b)的数组数组这在我使用时有效

each val in users
    p.
        val

我脚本的其他地方。

实际上,我现在正在从事Web开发,这是我正在从事的第一个工作。我试图从我的主应用程序传递一个变量,如app.get('/',(req,res)=> {getdata()。then(record => {...

html express pug
1个回答
0
投票
script.意味着后面的所有内容都被解释为文字。您仍然可以使用代码,但是语法不同:
© www.soinside.com 2019 - 2024. All rights reserved.