简体   繁体   English

如何调用组件道具的方法 - VueJS?

[英]How can I call a method to a component prop - VueJS?

I'm trying to format a prop with a method that I've created.我正在尝试使用我创建的方法格式化道具。 Is it possible?可能吗?

I'm looking for something like this:我正在寻找这样的东西:

My component:我的组件:

props:{
      title: String,
      min: String,
      formatedDate: this.formateDate(formatedDate)
}

Where I call this component the date is started as a empty string, but I change that value by a date-picker.在我调用此组件的地方,日期以空字符串开始,但我通过日期选择器更改了该值。

Is it possible?可能吗? Thanks a lot!非常感谢!

You could create a computed property based on that prop which uses the method:您可以基于使用该方法的道具创建计算属性:

props:{
      title: String,
      min: String,
      date: String
},

computed:{
    formatedDate(){
       return this.formateDate(this.date)
    }
}

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

相关问题 如何在 React 组件道具上使用 filter 方法? - How can I use the filter method on a React component prop? 我可以更改绑定到 VueJS 中另一个变量的组件道具变量吗 - Can i change component prop variable binded to another variable in VueJS 如何使用 VueJS 2 在变异方法中调用方法? - How can I call a method within mutation method using VueJS 2? 如何更新 Dropzone VueJs 组件上的 prop 选项值? - How do I update prop options value on the Dropzone VueJs component? 如何将组件的方法作为 prop 传递给子组件? [反应] - How can I pass a component's method as a prop to a child component? [REACT] Vue.js如何将数据作为道具传递给子组件 - Vuejs how to pass data as a prop to a child component VueJs 2:如何在另一个组件中显示道具? - VueJs 2: How to display prop in another component? 我如何绑定到已通过prop传递给子组件的函数,以便可以在子组件的函数中调用它 - How do I bind to a function that has been passed in to a child component via a prop so that I can call it in a function in the child component Vuejs 方法 ajax 调用组件上的其他方法 - Vuejs method ajax call other method on component 如何将组件作为道具传递给 React 中的另一个组件? - How can I pass a component as a prop into another component in React?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM