Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import { LitElement, html } from 'lit-element';
  2.  
  3. class SimpleGreeting extends LitElement {
  4. constructor() {
  5. super();
  6. this.model = {
  7. currentThing: 'optionA',
  8. things: [ 'optionA', 'optionB' ]
  9. };
  10. }
  11.  
  12. onSelect(e) {
  13. this.model.currentThing = e.target.value;
  14. this.render();
  15. }
  16.  
  17. render(){
  18. return html`<select @change=${e => this.onSelect(e)}>
  19. ${this.model.things.map(thing =>
  20. html`<option value="${thing}">${thing}</option>` )}
  21. </select>
  22. <div>
  23. ${this.displaySelected()}
  24. </div>`;
  25. }
  26.  
  27. displaySelected() {
  28. switch(this.model.currentThing) {
  29. case 'optionA': return html`<span>A_A_A_A_A_A</span>`;
  30. case 'optionB': return html`<span>B_B_B_B_B_B</span>`;
  31. }
  32. }
  33. }
  34.  
  35. customElements.define('simple-greeting', SimpleGreeting);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement