Skip to content

Recommended way of including header scripts in build process? #60

Answered by sergejcodes
james0r asked this question in Q&A
Discussion options

You must be logged in to vote

Hi 👋,

here's an example based on a dropdown component:

  1. create an alpine directory in your source folder src/alpine
  2. create a file called dropdown.js in your alpine directory src/alpine/dropdown.js with the following content:
export default {
  name: 'dropdown',
  component () {
    return {
      show: false,
      open() { this.show = true },
      close() { this.show = false },
      isOpen() { return this.show === true }
    }
  }
}
  1. add the following code to any .liquid file:
<div x-data="dropdown()">
  <button x-on:click="open">Open</button>

  <div x-show="isOpen()" x-on:click.away="close">
    // Dropdown
  </div>
</div>
  1. your src/main.js file should look something like the follo…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@james0r
Comment options

@james0r
Comment options

@sergejcodes
Comment options

@james0r
Comment options

Answer selected by james0r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants