本文整理匯總了TypeScript中mithril.route.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript route.get方法的具體用法?TypeScript route.get怎麽用?TypeScript route.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mithril.route
的用法示例。
在下文中一共展示了route.get方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: m
view: () => {
if (window.username) {
return m(
"div.user-menu",
window.username,
m(
"button",
{
onclick: e => {
e.target.disabled = true;
store
.logOut()
.then(() => {
location.hash = "";
location.reload();
})
.catch(err => {
e.target.disabled = false;
notifications.push("error", err.message);
});
return false;
}
},
"Log out"
)
);
} else {
return m(
"div.user-menu",
m(
"a",
{
href:
"#!/login?" + m.buildQueryString({ continue: m.route.get() })
},
"Log in"
)
);
}
}
示例2: setTimeout
setTimeout(() => {
console.assert(m.route.get() === "/b");
}, FRAME_BUDGET);
示例3: view
// http://mithril.js.org/route.html#wrapping-a-layout-component
////////////////////////////////////////////////////////////////////////////////
{
const Home = {
view() {
return "Welcome";
}
};
const state = {
term: "",
search() {
// save the state for this route
// this is equivalent to `history.replaceState({term: state.term}, null, location.href)`
m.route.set(m.route.get(), null, { replace: true, state: { term: state.term } });
// navigate away
location.href = "https://google.com/?q=" + state.term;
}
};
const Form: m.Comp<{term: string}, {}> = {
oninit(vnode) {
state.term = vnode.attrs.term || ""; // populated from the `history.state` property if the user presses the back button
},
view() {
return m("form", [
m("input[placeholder='Search']", { oninput: m.withAttr("value", v => { state.term = v; }), value: state.term }),
m("button", { onclick: state.search }, "Search")
]);