Can Onsen be used without Angular? I would rather use Aurelia

你说的曾经没有我的故事 提交于 2019-12-21 22:32:37

问题


Can Onsen be used without Angular?
Can Aurelia data bind to Onsen?


回答1:


Yes, it can be used without Angular.

You would need to take advantage of their css, and develop your custom components like the way they did for Angular.

For example, a simple ons-list Custom Element would be something like:

ons-list

ons-list.html

<template>
  <ul class="list ${inset ? 'list--inset' : ''}">
    <content select="ons-list-header"></content>
    <content select="ons-list-item"></content>
  </ul>
</template>

ons-list.js

import {bindable} from 'aurelia-framework'

export class OnsList {
  @bindable inset = false;
}

ons-list-header.html

<template>
  <li class="list__header">
    <content></content>
  </li>
</template>

ons-list-header.js

export class OnsListHeader {

}

ons-list-item.html

<template>
  <li class="list__item ${modifier === 'tappable' ? 'list__item--tappable' : modifier === 'chevron' ? 'list__item--chevron' : ''}">
    <content></content>
  </li>
</template>

ons-list-item.js

import {bindable} from 'aurelia-framework'

export class OnsListItem {
  @bindable modifier = ""; // other options: tappable | chevron
}

Usage (your-view.html)

<template>
  <ons-list>
    <ons-list-header>My header</ons-list-header>
    <ons-list-item>Item 1<ons-list-item>
    <ons-list-item>${myDynamicItemVariable}</ons-list-item>
  </ons-list>
</template>

Plunker: http://plnkr.co/edit/Lqm28H42zQbWiQBMHqXq?p=preview



来源:https://stackoverflow.com/questions/31747394/can-onsen-be-used-without-angular-i-would-rather-use-aurelia

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!