【问题标题】:Vue.js - Post method not working when pressing button [closed]Vue.js - 按下按钮时发布方法不起作用[关闭]
【发布时间】:2020-12-13 06:02:04
【问题描述】:

每当我尝试单击该按钮时,它都不会添加任何记录。但是当我输入输入字段@keyup.enter="addusers" 然后当我按下回车键时它正在工作。我希望它与添加按钮一起使用。谁能给我建议。

.row
      input(type='text', v-model='newUser')
      input(type='text', v-model='newMail')
      button.btn.btn-primary(type='button' @onclick="addUsers") Add

        
      .col-lg-12.text-left(v-for="user in users")
        p {{ user.name}}- {{user.email}}
 addUsers() {
      axios.post('https://jsonplaceholder.typicode.com/users', {
        name: this.newUser,
        email: this.newMail
      })
      .then(({data}) => {
        this.users.push(data);
       
      });

【问题讨论】:

  • 错字。 “@click”而不是“@onclick”

标签: vue.js vuejs2 axios vue-component pug


【解决方案1】:

点击事件应该写成@click而不是@onclick

 button.btn.btn-primary(type='button' @click="addUsers") Add

【讨论】:

    猜你喜欢
    • 2017-11-03
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    相关资源
    最近更新 更多