我有这个。它与文档中所说的完全相同。我认为 react-router-dom 模块很好,因为在其他组件中,BrowserRouter、Router 和 Link 对我有用
import { useHistory } from "react-router-dom"
import React from 'react'
export default function HomeButton() {
let history = useHistory()
function handleClick() {
history.push("/home")
}
return (
<button type="button" onClick={handleClick}>
Go home
</button>
);
}
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时会发生这种情况
类型错误:无法读取未定义的属性“推送”
我是 reactjs 的新手,请帮忙,谢谢
我正在为Pouch/CouchDB开发一个Vue插件,它将是开源的,但只要我能解决我遇到的问题:
目前我正在尝试使插件与Vuex紧密相似,具有内部状态,并检测更改,并在发生时呈现视图.
在Vue实例中我正在初始化一个对象,并且在该对象中,我试图使用defineReactive使两个或三个对象反应,直到这里它是好的.
但是当我尝试更改该对象内的某些值时,更改不会传播到View.但是,如果我明确地调用它.$ bucket._state.projects .__ ob __.dep.notify(),变化传播.
Vue实例的当前对象表示如下: Vue { $bucket: { _state: { projects: {} } } }
$bucket._state已初始化defineReactive.我相信它应该有效,但我不确定在这种情况下究竟是什么问题.
任何的想法?
部分代码,这里的类几乎相似 Vuex.Store({})
constructor(schema = {}) {
// Getting defineReactive from Vue
const { defineReactive } = Vue.util;
// Ignored Schema Keys
const ignoredKeys = [
'config',
'plugins'
];
// Internal Variables
this._dbs = {};
// Define Reactive Objects
defineReactive(this, '_state', {});
defineReactive(this, '_views', {});
// Local Variables
if (!schema.config) {
throw new Error(`[Pouch …Run Code Online (Sandbox Code Playgroud)