woki
woki

Reputation: 95

vue:Property or method "priceFilter" is not defined

import { priceFilter } from '../../commons/dom'

dom.js

export function priceFilter(e) {
  e.target.value = e.target.value.replace(/[^\d.]/g, "");
  e.target.value = e.target.value.replace(/^\./g, "");
  e.target.value = e.target.value.replace(/\.{2,}/g, ".");
  e.target.value = e.target.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  e.target.value = e.target.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
}

Property or method "priceFilter" is not defined on the instance but referenced during render.

Upvotes: 0

Views: 134

Answers (2)

EJL
EJL

Reputation: 205

your're priceFilter should look like this if you are calling a js file (dom.js)

// this is dom.js
export default {
      priceFilter(e) {
         e.target.value = e.target.value.replace(/[^\d.]/g, "");
         e.target.value = e.target.value.replace(/^\./g, "");
         e.target.value = e.target.value.replace(/\.{2,}/g, ".");
         e.target.value = e.target.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
         e.target.value = e.target.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
     }
}

and use it this way

import priceFilter from '../../common/dom'
// if in vue instance, use it in methods object
....
methods: {
   sampleUsage(e) {
      priceFilter(e);
   }
}

Upvotes: 0

Decade Moon
Decade Moon

Reputation: 34286

As the error message indicates, priceFilter needs to be defined on the component instance for it to be usable from the template. Module/global functions are not accessible from the template, only stuff defined on the Vue instance is.

import { priceFilter } from '../../commons/dom'

export default {
  methods: {
    priceFilter
  }
}

Upvotes: 1

Related Questions