Created
August 30, 2018 08:06
-
-
Save Musinux/82e5bbd42d76170a42f84178e13dee29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* globals Vue */ | |
| ;(function () { | |
| 'use strict' | |
| const template = ` | |
| <section id="accueil"> | |
| <h1>Titre de ma page d'accueil</h1> | |
| <p>Mon super texte</p> | |
| </section> | |
| ` | |
| Vue.component('accueil', { | |
| template: template | |
| }) | |
| })() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="fr"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Titre de la page</title> | |
| <style> | |
| nav ul li { | |
| display: inline-block; | |
| border: 1px solid red; | |
| width: 200px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <main id="app"> | |
| <nav> | |
| <ul> | |
| <li v-on:click="currentPage = 'accueil'">Accueil</li> | |
| <li v-on:click="currentPage = 'quisommesnous'">Qui sommes-nous ?</li> | |
| </ul> | |
| </nav> | |
| <accueil | |
| v-if="currentPage === 'accueil'"> | |
| </accueil> | |
| <section v-else-if="currentPage === 'quisommesnous'" id="quisommesnous"> | |
| <h1>Ceci est la page qui sommes-nous ?</h1> | |
| <p>Ceci est le texte qui décrit qui je suis</p> | |
| </section> | |
| <section v-else-if="currentPage === 'liste'" id="liste"> | |
| <input type="text" v-model="filter"> | |
| <button v-on:click="menu = 'dessert'">Cliquez !</button> | |
| <ul> | |
| <li v-for="item in myFilter()">{{ item.id }} {{ item.type }}</li> | |
| </ul> | |
| </section> | |
| </main> | |
| <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> | |
| <script src="accueil.component.js"></script> | |
| <script> | |
| const app = new Vue({ | |
| el: '#app', | |
| data: { | |
| currentPage: 'liste', | |
| filter: '', | |
| menu: '', | |
| myList: [{ | |
| id: 1, | |
| type: 'dessert' | |
| }, { | |
| id: 2, | |
| type: 'entrée' | |
| }, { | |
| id: 3, | |
| type: 'entrée' | |
| }, { | |
| id: 4, | |
| type: 'dessert' | |
| }] | |
| }, | |
| methods: { | |
| myFilter () { | |
| if (this.filter !== '') { | |
| return this.myList.filter(elem => elem.type.indexOf(this.filter) !== -1) | |
| } else if (this.menu !== '') { | |
| return this.myList.filter(elem => elem.type === this.menu) | |
| } | |
| } | |
| } | |
| }) | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment