[英][Vue warn]: Failed to resolve filter: concat surname
I am new with vue and trying to create a filter , I have create filter successfully with just data element but when I try to create with inline argument it gives me a above error .我是 vue 新手并尝试创建过滤器,我仅使用数据元素成功创建了过滤器,但是当我尝试使用内联参数创建时,它给了我上述错误。 I have also try with string instead of variable but it's not working.我也尝试使用字符串而不是变量,但它不起作用。
My filter like this我的过滤器是这样的
Vue.filter("concat", (value, surname) => {
return value + surname;
});`
and component like this和这样的组件
<template>
<div>
<h1>{{ firstName | concat surname}}</h1>
</div>
</template>
<script>
export default {
name: "FilterComponent",
data() {
return {
firstName: "Alex",
surname: "Johnson",
};
},
};
</script>
You can't use filter like this.你不能像这样使用过滤器。 If you want to pass surname as an argument to your filter you can do this (val will be firstname in the function):如果您想将 surname 作为参数传递给您的过滤器,您可以这样做(val 将是函数中的名字):
<template>
<div id="app">
<h1> {{ firstname | concat(surname) }} </h1>
</div>
</template>
<script>
export default {
name: "App",
data () {
return {
firstname : "FirstName",
surname : "LastName"
}
},
filters: {
concat : function (val, surname) {
return val + surname // will return full name
}
}
};
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.