R
R
Romi2022-01-03 11:40:50
Vue.js
Romi, 2022-01-03 11:40:50

How to make VSC properly accept Blade embedded in Vue like {!! $someVar !!} - and didn't paint it red?

It so happened that now I have to create a mutant and inject PHP variables in the Blade template right in Vue, like:

<script>
            new Vue({
                el: '#app',
                data: function() {
                    return {
                        var: {!! $someVar !!}
                    }
                },
                methods: {},
                mounted() {},
            })
</script>

Works. But VSC paints red var: {!! $someVar !!}and everything behind it, and swears:

Non-null assertions can only be used in TypeScript files.

By googling, I found a "solution" - disable JS validation in html files altogether. But, this is not an option.

There is also a more acceptable solution: inject PHP through a regular . Well, why not, of course. Works and does not paint in red. But then this mutant code really becomes a mutant mutant. In addition, it seems to be trying to escape it somehow (I don’t remember exactly, but something didn’t go there yesterday, when trying to find a suitable solution). If who faced a question - prompt please any simple and elegant decision. <?= $someVar ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2022-01-03
@By_Engine


please some simple and elegant solution

Douse with gasoline and burn

S
Sergey delphinpro, 2022-01-03
@delphinpro

Not much better, but at least you can remove scripts from html

<script>const someVar =  {!! $someVar !!};</script>

new Vue({
  el: '#app',
  data: function() {
    return {
      var: window.someVar
    }
  },
  methods: {},
  mounted() {},
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question