简体   繁体   English

如何在Riot.js中引用输入字段的值?

[英]How to reference an input fields value in Riot.js?

<hello-world>
  <form action="">
    <input type="text" ref="inputValue" placeholder="type a name" />
    <input type="submit" onclick="{trigger_printName}" />
  </form>

  <script>

    this.trigger_printName = e => {
      e.preventDefault();
      console.log(e.target.value);
      console.log(this.refs.inputValue.value)
    };
  </script>
</hello-world>

I am trying to access the value of the users input in the input field. 我正在尝试访问在输入字段中输入的用户的值。 Console logging e.target.value returns an empty string and console logging this.refs.inputValue.value says "Cannot read property 'inputValue' of undefined" 控制台日志记录e.target.value返回一个空字符串,控制台日志记录this.refs.inputValue.value说“无法读取未定义的属性'inputValue'”

Turns out I had some how installed a very old version of riot+compiler.min.js. 原来,我有一些如何安装非常旧的riot + compiler.min.js版本。 after updating the file to the current v3.13.2 it works just fine. 将文件更新到当前的v3.13.2后,它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM