Skip to content
Mithril.js 2
Main Navigation AnleitungAPI

Deutsch

English
简体中文
繁體中文
Español
Français
Русский
Português – Brasil
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Deutsch

English
简体中文
繁體中文
Español
Français
Русский
Português – Brasil
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Aussehen

Sidebar Navigation

Erste Schritte

Installation

Einfache Anwendung

Ressourcen

JSX

ES6+ in älteren Browsern

Animationen

Testen

Beispiele

Integration von Drittanbietern

Pfadverarbeitung

Schlüsselkonzepte

Virtuelle DOM Knoten

Komponenten

Lebenszyklus-Methoden

Keys

Das Auto-Redraw-System

Sonstiges

Framework-Vergleich

Migration von v1.x

Migration von v0.2.x auf v2.x

API

Auf dieser Seite

Integration von Drittanbietern ​

Die Integration mit Bibliotheken von Drittanbietern oder Vanilla-JavaScript-Code kann über Lifecycle-Methoden erfolgen.

noUiSlider Beispiel ​

javascript
/** NoUiSlider Wrapper-Komponente */
function Slider() {
  var slider;

  return {
    oncreate: function (vnode) {
      // Initialisiere die Drittanbieter-Bibliothek hier
      slider = noUiSlider.create(vnode.dom, {
        start: 0,
        range: { min: 0, max: 100 },
      });
      slider.on('update', function (values) {
        vnode.attrs.onChange(values[0]);
        m.redraw();
      });
    },
    onremove: function () {
      // Zerstöre die Drittanbieter-Bibliothek beim Entfernen
      slider.destroy();
    },
    view: function () {
      return m('div');
    },
  };
}

/** Demo-App-Komponente */
function Demo() {
  var showSlider = false;
  var value = 0;

  return {
    view: function () {
      return m(
        '.app',
        m(
          'p',
          m(
            'button',
            {
              type: 'button',
              onclick: function () {
                showSlider = !showSlider;
              },
            },
            showSlider ? 'Slider entfernen' : 'Slider erstellen'
          )
        ),
        showSlider &&
          m(Slider, {
            onChange: function (v) {
              value = v;
            },
          }),
        m('p', value)
      );
    },
  };
}

m.mount(document.body, Demo);

Live Demo

Bootstrap FullCalendar Beispiel ​

javascript
/** FullCalendar Wrapper-Komponente */
var FullCalendar = {
  oncreate: function (vnode) {
    console.log('FullCalendar::oncreate');
    $(vnode.dom).fullCalendar({
      // Füge hier deine anfänglichen Optionen und Rückrufe ein
    });
  },
  onremove: function (vnode) {
    // Führe hier alle Zerstörungs- und Bereinigungsmethoden aus.
    $(vnode.dom).fullCalendar('destroy');
  },
  view: function (vnode) {
    return m('div');
  },
};

/** Demo-App-Komponente */
function Demo() {
  var fullCalendarEl;

  function next() {
    $(fullCalendarEl).fullCalendar('next');
  }

  function prev() {
    $(fullCalendarEl).fullCalendar('prev');
  }

  return {
    view: function (vnode) {
      return [
        m('h1', 'Calendar'),
        m(FullCalendar, {
          oncreate: function (vnode) {
            fullCalendarEl = vnode.dom;
          },
        }),
        m(
          'button',
          {
            onclick: prev,
          },
          'Mithril.js Schaltfläche -'
        ),
        m(
          'button',
          {
            onclick: next,
          },
          'Mithril.js Schaltfläche +'
        ),
      ];
    },
  };
}

m.mount(document.body, Demo);

Live Demo

Pager
Vorherige SeiteBeispiele
Nächste SeitePfadverarbeitung

Veröffentlicht unter der MIT-Lizenz.

Copyright (c) 2024 Mithril Contributors

https://mithril.js.org/integrating-libs.html

Veröffentlicht unter der MIT-Lizenz.

Copyright (c) 2024 Mithril Contributors