0

In my .vue file within my template section I have:

<a v-bind:href="'javascript:artist(\'' + _.escape(artist) + '\')'">

which is using the Lodash function _.escape. This generates a string of errors the first of which is:

[Vue warn]: Property or method "_" is not defined on the instance but referenced during 
render.

However in the same file in the script section of the component I am happily and successfully using a range of Lodash functions.

This is a Laravel app and in my app.js file I have this code:

require('./bootstrap');

window.Vue = require('vue');
import VueRouter from 'vue-router';

window.Vue.use(VueRouter);

import lodash from 'lodash';
Object.defineProperty(Vue.prototype, '$lodash', { value: lodash });

import SearchHome from './components/search.vue';

const routes = [
{
    path: '/',
    components: {
        searchHome: SearchHome
    }
},

]

const router = new VueRouter({ routes })

const app = new Vue({ router }).$mount('#app')

Can anyone please help me?

2
  • I have also tried <a v-bind:href="'javascript:artist(\'' + this.$lodash.escape(artist) + '\')'"> Commented Jan 19, 2018 at 12:19
  • SORRY! I have solved it. It should of course be $lodash.escape(). Commented Jan 19, 2018 at 12:26

1 Answer 1

3

Try to use a computed value instead. This will improve readability. Avoid complex operation in a binding.

<a :href="artistLink">

And in the script

import _ from 'lodash'

export default {
    computed: {
       artistLink () {
           return 'javascript:artist(\'' + _.escape(this.artist) + '\')'
       }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.