Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue filter dont work on v-html #6056

Closed
paulocoutinhox opened this issue Jul 7, 2017 · 4 comments
Closed

Vue filter dont work on v-html #6056

paulocoutinhox opened this issue Jul 7, 2017 · 4 comments

Comments

@paulocoutinhox
Copy link

Version

2.3.4

Reproduction link

https://github.com/prsolucoes/gohc-web-app/blob/vuejs/src/components/HealthcheckList.vue

Steps to reproduce

1 - Create any component
2 - Create any filter that return HTML and register with Vue.filter
3 - Use the filter with v-html to render original html from filter:

<span v-html="props.row.status | hcStatusFormat"></span>

What is expected?

Render the HTML returned from filter

What is actually happening?

Error:

[Vue warn]: Property or method "hcStatusFormat" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

found in

---> <HealthcheckList> at /Users/paulo/Developer/workspaces/node/gohc-web-app/src/components/HealthcheckList.vue
       <App> at /Users/paulo/Developer/workspaces/node/gohc-web-app/src/App.vue
         <Root>

The only way that works:

<span v-html="$options.filters.hcStatusFormat(props.row.status)"></span>
@sqal
Copy link
Contributor

sqal commented Jul 7, 2017

Documentation is clear on this matter - https://vuejs.org/v2/guide/syntax.html#Filters (it only works inside mustache interpolations and v-bind expressions)

The only way that works:
<span v-html="$options.filters.hcStatusFormat(props.row.status)"></span>

or you can call function declared in the methods object

// edit: i just realized, you can use syntax:

 <div :inner-html.prop="props.row.status | hcStatusFormat"></div>

@posva
Copy link
Member

posva commented Jul 7, 2017

what @sqal said 🙂

@posva posva closed this as completed Jul 7, 2017
edouard-lopez added a commit to parlr/lsf that referenced this issue Nov 16, 2017
@ngcdev
Copy link

ngcdev commented Sep 7, 2018

Definitely what @sqal discovered is the best solution and perhaps should be documented. Using $options completely defeats the purpose of using it as a "filter". So might as well create a method.
But if we still want to use it as a filter, then the documentation should mention to bind it to the inner-html DOM property

@andrew441
Copy link

Documentation is clear on this matter - https://vuejs.org/v2/guide/syntax.html#Filters (it only works inside mustache interpolations and v-bind expressions)

The only way that works:
<span v-html="$options.filters.hcStatusFormat(props.row.status)"></span>

or you can call function declared in the methods object

// edit: i just realized, you can use syntax:

 <div :inner-html.prop="props.row.status | hcStatusFormat"></div>

Great, this works for me! thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants