Created
September 6, 2019 05:59
-
-
Save bengfarrell/0056a79751a9a63073b23e18682e7f74 to your computer and use it in GitHub Desktop.
LitElement not updating
This file contains 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
import { LitElement, html } from 'lit-element'; | |
class SimpleGreeting extends LitElement { | |
constructor() { | |
super(); | |
this.model = { | |
currentThing: 'optionA', | |
things: [ 'optionA', 'optionB' ] | |
}; | |
} | |
onSelect(e) { | |
this.model.currentThing = e.target.value; | |
this.render(); | |
} | |
render(){ | |
return html`<select @change=${e => this.onSelect(e)}> | |
${this.model.things.map(thing => | |
html`<option value="${thing}">${thing}</option>` )} | |
</select> | |
<div> | |
${this.displaySelected()} | |
</div>`; | |
} | |
displaySelected() { | |
switch(this.model.currentThing) { | |
case 'optionA': return html`<span>A_A_A_A_A_A</span>`; | |
case 'optionB': return html`<span>B_B_B_B_B_B</span>`; | |
} | |
} | |
} | |
customElements.define('simple-greeting', SimpleGreeting); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment