Home > Software design >  Alpine Expression Error: show is not defined
Alpine Expression Error: show is not defined

Time:11-09

alpinejs not working when following installation instructions. I am following the instructions from Codechef to install alpine.

I use it in my blade.php like this:

 <script src="{{ asset('js/alpine.js') }}"></script>
 <!-- other elements ommitted for brevity -->
 <div x-data=""{ show: false}>
     <button @click="show = ! show">{{ __("Position")  }}</button>
     <div x-show="show">
         <a href="#">One</a>
         <a href="#">Two</a>
         <a href="#">Three</a>
     </div>
 </div>

My layout.blade.php contains the line

   <script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>

When I open the page, I get the following error:

Alpine Expression Error: show is not defined

Expression: "show"

What could be missing?

CodePudding user response:

Please try this:

<div x-data="{show: false}">

(you wrote instead:

<div x-data=""{show: false}>

that is not correct)

  • Related