I’m trying to use Blade in my Vue file carousel-signUp.vue
Like:
JavaScript
x
8
1
<template>
2
<div>
3
<form action="{{route('dump')}}" method="POST" >
4
/* Some code here...*/
5
</form>
6
</div>
7
</template>
8
But in the end I’m getting an error.
The compiler can’t understand the difference between Vue syntax and Blade syntax. How can I define Blade syntax in Vue files?
Or, does anyone have an idea how to use {{route('dump')}}
value in my vue
file?
Advertisement
Answer
A better solution might be to output the desired blade variables to (hidden) html and select that html in your Vue code. Escape the curly braces for Vue with @
.
Your blade example.blade.php
JavaScript
1
8
1
<div id="content" hidden>
2
{{ bladeVar }}
3
</div>
4
5
<div id="app">
6
@{{ vueVar }}
7
</div>
8
The result of that blade (how it will look in the cached file) + javascript (Vue)
JavaScript
1
6
1
var app = new Vue({
2
el: '#app',
3
data: {
4
vueVar: document.getElementById('content').innerHTML + 'from Vue'
5
}
6
});
JavaScript
1
8
1
<script src="https://unpkg.com/vue"></script>
2
<div id="content" hidden>
3
Hello world
4
</div>
5
6
<div id="app">
7
{{ vueVar }}
8
</div>