E
E
Evgeny Romashkan2018-06-21 23:06:28
Laravel
Evgeny Romashkan, 2018-06-21 23:06:28

How to implement blade code output inside blade so that vue does not throw errors on variables (or how to escape curly braces in Vue)?

{!! !!} displays code like {!! $var !!}, but if inside $var there is a string ' {{ $var2 }}' ( $var = '{{ $var2 }}'), the burden of displaying the variable inside {{ .. }} is taken by vue, and eventually gives an error

[Vue warn]: Property or method "$var" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

(found in <Root>)

Is it possible to tell vue that variables inside, say, a certain div should be escaped?
This vue code also fails to render:
<div class="body"><span v-html="{!! $var !!}"></span></div>

UPD: So far, 2 options have been found for myself
1. Do not render from php, but pass data to vue and show via v-html
2. Set other delimiters for Vue variables:
const app = new Vue({
    delimiters: ['${', '}'],
    el: '#app'
});
.
Option 2 is bad because I have one instance of vue per site, and somehow I would not really like to stick to a non-standard variable entry throughout the site ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Romashkan, 2018-06-23
@EvgeniiR

UPD: Found the answer. Need to use v-pre

V
vism, 2018-06-22
@vism

@{{}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question