我是新手重新组合,我想我忘记了一些明显的东西。我的网页即将启动并正常工作,但是当我点击单选按钮时似乎没有更新。基本上,我想要做的是当单击单选按钮时,它将我的value-name
原子更新为2.这样做会导致页面刷新,因为函数display-val
依赖于{{1 }}。然而,没有任何事情发生。
我觉得我应该订阅某些内容,以便value-name
知道更新。
这是我的代码:
display-val
答案 0 :(得分:2)
请查看此示例,您将了解重新构建应用程序的外观。
https://day8.github.io/re-playground/?gist-id=saskali/1398f41345ea4df551b0c370ac1ac822
TL; DR
()
代替[]
代理组件我认为您需要阅读所有重新构建的文档,重新构建文档很棒,应该反复阅读。
https://github.com/Day8/re-frame
以下是您理解
的最简单示例(ns simple.core
(:require [reagent.core :as reagent]
[re-frame.core :as rf]
[clojure.string :as str]))
(rf/reg-event-db ;; sets up initial application state
:initialize
(fn [_ _]
{:counter 0}))
(rf/reg-event-db
:counter-inc
(fn [db [_]]
(update db :counter inc))) ;; compute and return the new application state
(rf/reg-sub
:counter
(fn [db _]
(:counter db))) ;; return a query computation over the application state
(defn ui
[]
[:div
[:h1 "Hello world, it is now"]
[:span @(rf/subscribe [:counter])]
[:button {:on-click #(rf/dispatch [:counter-inc])}
"inc"]])
(defn ^:export run
[]
(rf/dispatch-sync [:initialize]) ;; puts a value into application state
(reagent/render [ui] ;; mount the application's ui into '<div id="app" />'
(js/document.getElementById "app")))
(run)