代码之家  ›  专栏  ›  技术社区  ›  Fernando Santiago

如何在vue3中从setup调用prop函数

  •  0
  • Fernando Santiago  · 技术社区  · 5 年前

    我有下一个代码:

    HTML:

    <p @click="changeForm">Iniciar sesion</p>
    

    JS

    export default {
       name: "Register",
       props: {
          changeForm: Function,
       },
       setup() {
          //How can i call props changeForm here???
       }
    }
    

    如何从JS调用props函数?另一种方法是触发点击我的p元素,这可能吗?

    我正在使用vue 3。我已经用this.changeForm和props.changeForm进行了测试,但没有成功。

    1 回复  |  直到 5 年前
        1
  •  18
  •   Dan    5 年前

    这个 setup 功能接收 props 作为其第一个论点:

    export default {
       name: "Register",
       props: {
         changeForm: Function,
       },
       setup(props) {            // receive `props` argument
         props.changeForm();     // use it to access `changeForm`
       }
    }
    
    推荐文章