Vuejs view source - I can still see directives after compilation - compilation

When I compile my vuejs and then do a view source (chrome) I still see the directives and variable place holders?
<nav #click="toggleNav"></nav>
<span class="title">{{ pageName }}</span>
I am pulling it in via
<script src="https://unpkg.com/vue/dist/vue.js"></script>
When I try to validate via the W3c I get loads of errors. Should these not be compiled down?
Should I make anything with a directive on it a component so it does not show in my html?

Related

Laravel session message as toastr notifications

How to convert the below session message to Toastr message without changing the controller code. In short i want to use toastr for all session messages without touching the controller code.
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
I'm using basic bootstrap 4 and laravel 5.6
Since toastr is a JS library, it needs to be included on the page calling the snippet (either on the same page or before a .blade.php directive such as #include() or #yield()):
<script type="text/javascript" src="/path/to/toastr.js"></script>
Then, modify the snippet to use toastr:
#if(session("status"))
<script type="text/javascript">
toastr.info("{{ session("status") }}");
<script>
#endif
.blade.php will convert session("status") to a string, which toastr will process and display as an info message.
Great response from friend Tim Lewis, but I faced yet another challenge for trying to use the toatsr from the AdminLte3 template automatically installed on Laravel 6.x.
Below what I did to complement and make it work in my project.
According to the AminLte3 documentation, the additional inclusion of CSS or JS is through sections
Section example for adding CSS
#section('css')
<link rel="stylesheet" href="/css/admin_custom.css">
#stop
Section example for adding JS
#section('js')
<script> console.log('Hi!'); </script>
#stop
So I needed to add the Toastr library and then include my .blade file for alerts along with the JS section
JS section with the alerts .blade file
#section('js')
<script src="myPath/toastr.js"></script>
#include('myPath.alerts')
#stop
Alerts .blade file
#if(session("status"))
<script type="text/javascript">
toastr.info("{{ session("status") }}");
<script>
#endif

Laravel blade.php use JavaScript compiled by mix to app.js

I'd like to use a JavaScript function in my blade.php file. I created the xyz.js file with a very simple function
function picture(soemthing){
document.getElementById('idXYZ').src = "example.com";
}
Then I added this file to the webpack.mix.js config:
mix.js(['resources/assets/js/app.js', 'resources/assets/js/xyz.js'], 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
and run: npm run dev. So far so good, npm compiled my script and the picture function was included in the app.js file. Now I'd like to add a form in blade.php and call the picture function on click. I created the following blade.php file:
#extends('layouts.app')
#section('content')
<div class="container">
<form>
Enter url: <input type="text" id="someID">
<input type="button" onclick="picture($('#someID').val())" value="Click"/>
</form>
</div>
<script src="{{ mix('js/app.js') }}"></script>
#endsection
And here I got really lost (btw: I was always the backend guy). On page reload browser displays
[Vue warn]: Error compiling template: Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as , as they will not be parsed.
And when I click the button I have
Error new:76 Uncaught ReferenceError: xyz is not defined
I understand that the first errors says that the app.js file was not loaded and that's the reason why picture is not found. How should I include app.js or any other compiled by mix JavaScript file? Is it really the tag causing this problem?
Try this I solved me
<script src="{{ asset('js/app.js') }}?time={{ time() }}"></script>
" I think not all browsers support this "
I think you're getting the error because you're placing a new script tag inside of the vue.js application div.
If you're opening your layout file app.blade.php there is a div with id="app" and inside it you're having your content section yield. Side-effect means that you shouldn't load a new script inside a Vue.js template.
The script should be in your layout at the end of the body tag. Also the script tag should look like this:
<script src="{{ asset('js/app.js') }}"></script>
Then your script should be available. But I would have a look at Vue.js and how you're handling click events there. click handler docs

Firefox requesting content inside HTML5 template before activation

I was debugging my web app using DevTools when I noticed that Firefox is requesting url defined in src attribute of an img that is located inside a HTML5 template tag, while Chrome doesn't.
I'm using the last version (50.0).
Is this a bug?
Example below:
<template id="object-img">
<div class='object-container'>
<div>
<img src="cacaca.jpg" class="img-responsive" alt="imagem" />
</div>
</div>
</template>
It's a kind of optimization from Firefox.
The image is requested only the first time if it is not already in the browser's history / cache. Subsequent reload of the page won't trigger the request again.
The problem is that the image inside the <template> is requested before the following but normal images in the rendered DOM, which could be counterproductive in some situations. A solution is to put the <template> after the other images.
Note: the template specifications state that the elements in the template are not rendered, but they are parsed. They say nothing about preloading of referenced resources.

Highlight.js not workng on Laravel 5.3 Target Page

I am developing a Blog with Laravel 5.3. In the Add Post Page, I use CKEDITOR with Code Snippet Plugin. In this area Everything is OK. Code added in the textarea field by plugin is also become highlighted.
In the Target Page I added:
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/default.min.css">
In the Header section of the page.
and
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
In the footer section of the page.
The page received the following html code from the Database.
<p>The place for Laravel Blade Template.</p>
<pre>
<code class="language-html"><div><h1>
This is a Header</h1></div></code></pre>
<p> </p>
which is showing like this.
<p>The place for Laravel Blade Template.</p> <pre>
<code class="language-html"><div><h1>This is a Header</h1></div></code>
</pre> <p> </p>
So the code section is not highlighted.
How can I do that. What's my wrong? I need Help.
The problem is, that the whole HTML code is escaped, so it won't be interpreted by the browser.
What you want is that only the content between <code class="language-html">...</code> is escaped, so that the Browser renders the code container correctly and that highlight.js can hook into the DOM object.
In Laravel 5 to output non escaped HTML you must use {!! !!}
An example of this:
{!!$myDatabaseHtml!!}

using ZURB Foundation with laravel

I am new to laravel so I am not sure how this can be achieved. I am using ZURB Foundation and trying to create a button in the page.
I use linkRoute always to redirect to a named route then redirect to a specific controller action. I have the below:
<body >
<h1 align="center">ShopCon.com</h1><br><br>
<a style="margin-left:50px;" href="{{ HTML::linkRoute('membersaccess', 'Members Access') }}" class="medium success button">Login or Register</a>
</body>
but when I render this, it shows like this
Members Access" class="medium success button">Login or Register
instead of showing the button and text within it and link to named route. How can this be fixed? I read something about macros but unable to clearly understand them or use them to achieve this.
Picture included for reference:
HTML::linkRoute produces an HTML anchor tag.
Since you only want the URL, use URL::route.

Resources