我是React,Clojure,ClojureScript和Reagent的新手,所以我可能缺少一些简单的东西。
我正在从此处(https://reagent-project.github.io)和默认的hello-world ClojureScript页面修改代码,以获取简单的登录页面。但是,每当我在用户名和密码字段中输入内容时,都不会发生任何事情。为什么会这样?
(ns cljs_test.core
(:require [reagent.core :as reagent :refer [atom]]))
(enable-console-print!)
;; define your app data so that it doesn't get over-written on reload
(defonce app-state (atom {:text "Hello world!"}))
(defn atom-input [state]
[:input {:type "text"
:style {:display "block"}
:placeholder "Username"
:value @state
:on-change (fn [event]
reset! state (-> event .-target .-value))}])
(defn atom-pw [state]
[:input {:type "password"
:style {:display "block"}
:placeholder "Password"
:value @state
:on-change (fn [event]
reset! state (-> event .-target .-value))}])
(defn loginForm [someUrl]
(let [unVal (atom "") pwVal (atom "")]
(fn []
[:div
[:p "Username: " @unVal]
[:p "Password: " @pwVal]
[atom-input unVal]
[atom-pw pwVal]
[:button "to-do submit button"]])))
(defn app []
[:div
[:div
[:h1 (:text @app-state)]
[:h3 "Edit this and watch it change!"]]
[loginForm ""]])
(reagent/render-component [app]
(. js/document (getElementById "app")))
(defn on-js-reload []
;; optionally touch your app-state to force rerendering depending on
;; your application
;; (swap! app-state update-in [:__figwheel_counter] inc)
)
感谢您的答复。
缺少括号。应该看起来像:
(defn atom-input [state]
[:input {:type "text"
:style {:display "block"}
:placeholder "Username"
:value @state
:on-change (fn [event]
(reset! state (-> event .-target .-value)))}])