Reputation: 17
Hello everyone so new to laravel here, I just want to ask how to put JS into the file that automatically created when running php artisan ui vue --auth
, because whenever I try to add it into resources/views/auth/register.blade.php
I get
[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.
sorry for random question I just want to know how, and also how to add css, thank you so much in advance
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Dashboard</div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
You are logged in!
</div>
</div>
</div>
</div>
more code here since they dont allow
@endsection
Upvotes: 0
Views: 585
Reputation: 1223
You're trying to add a <script>
to your blade @section
, which is why you're getting that error. There are a few ways to do this.
1.. Add your script tags to views/layouts/app.blade.php
right before the </body>
tag, for example:
<script></script>
</body>
</html>
2.. Place them in your <head>
tag and add the defer attribute
<script defer></script>
Your register.blade.php
and any other view that extends app.blade.php
will now have access to these scripts because it extends the app.blade.php
layout.
3.. Use the Blade @stack
directive to push your script to a stack. Stacks can be named, in this example lets simply use the name scripts
. Add this to register.blade.php
@push('scripts')
<script></script> <!-- Add your JS file or JS code -->
@endpush`
Now in the <head>
tag of your app.blade.php
you can place @stack('scripts')
Note: Only register.blade.php
will load this script, any other view that extends app.blade.php
will not have access to it.
Upvotes: 1