monx icon indicating copy to clipboard operation
monx copied to clipboard

Monx + Moon.Router

Open ksanderer opened this issue 7 years ago • 2 comments

Can you provide an example how to work with router and Monx?

require("./components/c1");
require("./components/c2");

Moon.use(Monx);
Moon.use(MoonRouter);

const store = new Monx({
  state: {
    count: 1
  },
  actions: {
    increment: (state, payload) => {
      state.count += payload;
    }
  }
});

const router = new MoonRouter({
    default: "/",
    map: {
        "/": "c1",
        "/:slug": "c2",
    }
});

var app = new Moon({
    router: router,
    el: "#app",
    store: store
});


/*
/components/c2.js
---------------------------------------
How can I use monx in child component?
*/
Moon.component("c2", {
    props: ['route'],

    data: function () {
        return {
            test: "test"
        }
    },

    template: `<div><a on-click='action.increment()'>{{ test }}</a></div>`,
});

ksanderer avatar Jan 15 '18 20:01 ksanderer

Hi.. Watching the architecture of these projects, probably you have to make the same issue on MoonRouter...

giorgionetg avatar Jun 28 '18 12:06 giorgionetg

Just use Monx as you normally would with a component — provide the store option.

Moon.component("c2", {
    props: ['route'],

    data: function () {
        return {
            test: "test"
        }
    },

    template: `<div><a on-click='action.increment()'>{{ test }}</a></div>`,

    store: store // This option must be provided to every component using the store
});

kbrsh avatar Jun 28 '18 13:06 kbrsh