Thursday 28 October 2021

How can I pass a value to init methods on import?

Let's assume I have component like this:

'use strict';

export default () => ({
    selected: false,
    init(selectedIndex: -1)
    {

    }

});

and I import it like this (using AlpineJS 3):

import Alpine from 'alpinejs'

window.Alpine = Alpine

window.Components = {};

import Tab from "./components/Tab";
window.Components.Tab = Tab;

Alpine.start();

How can I now pass value to init method?

When I have:

<div x-data="Components.Tab(0)">...</div>

value is obviously not passed to init method.

Although there is info in docs how to register component from a bundle and info how to pass initial parameters, there is no info how to pass initial parameters to component registered from a bundle



from How can I pass a value to init methods on import?

No comments:

Post a Comment