showing results for - "laravel vuejs assets 28 29"
Amir
24 Feb 2016
1//Inside the head section of the layout create a global reference
2//to the base asset path, something like this
3
4window._asset = '{{ asset('') }}';
5//Next step is to create a Vue mixin. In my case, a trans.js file with the following content:
6
7module.exports = {
8    methods: {
9        asset(path) {
10            var base_path = window._asset || '';
11            return base_path + path;
12        }
13    }
14}
15
16//Make sure you include it after Vue, for example:
17
18window.Vue = require('vue');
19Vue.mixin(require('./asset'));
20//and then you can use it inside all your Vue components.
21//Your original code would look like this
22
23<img :src="asset('admin/images/users/avatar-1.jpg')" width="35 px" height="23px">
24//Note the lack of {{ and the addition of : in this case,
25//since it is used as an attribute value.