我已升级到React Router V4,现在正在努力使用该history.push
方法.
我有一个index.js文件:
import React from "react";
import { render } from "react-dom";
import { BrowserRouter, Route } from 'react-router-dom';
import createBrowserHistory from 'history/createBrowserHistory';
const history = createBrowserHistory();
import { Main} from "./components/Main";
import { About } from "./components/About";
import { Cars} from "./components/Cars";
class App extends React.Component {
render() {
return (
<BrowserRouter history={history}>
<div>
<Route path={"/"} component={Main} />
<Route path={"/cars"} component={Cars}/>
<Route path={"/about"} component={About}/>
</div>
</BrowserRouter>
)
}
}
render(<App/>, window.document.getElementById("app"));
Run Code Online (Sandbox Code Playgroud)
然后我有另一个文件,在那里我添加了一个简单的返回到某个页面,如下所示:
import React from …
Run Code Online (Sandbox Code Playgroud) 我需要更改远程存储库的 url,所以我正在查看https://git-scm.com/docs/git-remote上的文档,但是当我这样做时:
git remote set-url git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)
我收到消息 usage: git remote set-url [--push] <name> <newurl> [<oldurl>]
我不太明白,我应该输入:
git remote set-url --push gitusername git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)
或者代表什么<name>
?我应该包括旧网址吗?
更新
所以当我输入:
git remote set-url --push origin git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)
在那种类型之后 git remote -v
我明白了:
origin git@github.com:oldusername/oldrepo.git (fetch)
origin git@github.com:gitusername/repository.git (push)
Run Code Online (Sandbox Code Playgroud)
如何更改提取?
在我的vue
应用程序中,我有一个表单,它应该检测每个更改。我尝试使用@change
和 也与观察者一起使用,但没有运气......
form: {
name: "",
surname: "",
email: "",
},
changed: false
Run Code Online (Sandbox Code Playgroud)
然后在我的模板中:
<form @change="hasChanged">
Run Code Online (Sandbox Code Playgroud)
然后是我的观察者和方法:
watch: {
form: {
handler: function(v) {
return this.hasChanged();
},
deep: true
}
},
methods: {
hasChanged(){
this.changed = true
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用......我做错了什么?
我在我的网站上使用外部银行贷款计算器,在输入特定金额后,它会自动计算贷款条件.
现在,出于显示原因,我需要从生成的值中提取一些数据.我想我可以用Jquery做到这一点,但我不确定为什么.
这是计算器插件生成的HTMl:
<section class="info">
<div class="graph on">
<div class="sums">
<dl data-type="capital">
<dt>
<span class="percent">2%</span>
</dt>
<dd>100.000</dd>
</dl>
<dl data-type="bankloan">
<dt>
<span class="percent">18%</span>
</dt>
<dd>400.000</dd>
</dl>
<dl data-type="mortage">
<dt>
<span class="percent">80%</span>
</dt>
<dd>1.500.000</dd>
</dl>
</div>
</div>
</section>
Run Code Online (Sandbox Code Playgroud)
我需要的是<dd>
-tag中的数据(纯文本)
有没有人有建议如何实现这一目标?
我正在使用pinia
并且我想知道如何更新对象内的属性。我在 中有一个对象数组state.cart
,其中是一些产品,它们都有一个名为 的属性quantity
。该属性可以更改,因此我需要“更新”购物车数据。
这是我尝试过的:
state: () => ({
cart: []
}),
actions: {
updateQuantityOfProduct(product, val) {
const prod = this.cart.find((item) => item.id === product.id)
prod.quantity = val
this.$patch({
cart: this.cart,
})
},
}
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用,因为购物车未更新和/或当我刷新时,尚未添加更新/更改(产品数量与更改前相同)
我该如何解决这个问题以及我做错了什么?
我尝试将文本粘贴到多个字段中,但格式只在第一个元素上被清除,而不是第二个等等。
我发现这个问题/sf/answers/841969551/工作正常,但同样,在多个元素上它不起作用。
所以我得到了这个 HTML
<div style="color:red">Some <em>rich</em> <span style="font-size:2em">HTML</span></div>
<br />
<div style="border:1px solid red" contenteditable></div>
<br />
<div style="border:1px solid red" contenteditable></div>
Run Code Online (Sandbox Code Playgroud)
和这个javascript:
document.querySelector("div[contenteditable]").addEventListener("paste", function(e) {
e.preventDefault();
var text = e.clipboardData.getData("text/plain");
document.execCommand("insertHTML", false, text);
});
Run Code Online (Sandbox Code Playgroud)
我有这个小提琴http://jsfiddle.net/tdjuc8es/
只需复制并粘贴Some rich HTML
- 文本,看看会发生什么
谁能帮帮我?
我正在使用这个裁剪工具https://github.com/fengyuanchen/cropper/。我有这个问题,如果我动态添加图像,图像周围会有一些透明背景。因此图像不适合容器,并且还可以在图像周围进行裁剪。我按照文档中的示例尝试摆脱透明背景,但没有成功。
这是我的代码:
<div id="imgWrap" style="max-height:400px;min-height:400px">
<img id="img" src="" /> // Image gets added dynamically
</div>
Run Code Online (Sandbox Code Playgroud)
javascript
var reader = new FileReader();
reader.onloadend = function () {
var img = $('#imgWrap img');
img.attr('src', reader.result);
img.cropper({
aspectRatio: 1 / 1,
autoCropArea: 0.65,
guides: false,
strict: true,
highlight: false,
responsive:true,
dragCrop: false,
movable: true,
resizable: true,
zoomable: true,
touchDragZoom:true,
rotatable: false,
minCropBoxWidth:105,
minCropBoxHeight:105,
built: function () {
// cropper-container is the element where the image is placed
$('.cropper-container').cropper('setCanvasData', {
left: 0, …
Run Code Online (Sandbox Code Playgroud) 我想从选择列表中获取默认选项的数据属性.
我有这个:
<select className="form-control" id="select" onChange={(e) => state.selectedOptionValue(e)} value={state.selectedOption}>
{data.map((option, i) => <Options key={i} option={option}/>)}
</select>
const Options = observer(({ state, option }) => (
<option data-option-id={option.id} value={option.displayText}>
{option.displayText}
</option>
))
Run Code Online (Sandbox Code Playgroud)
然后在我的状态文件中我有onChange
处理程序:
async selectedOptionValue (e) {
this.selectedOption = e.target.value
this.optionId = e.target.options[e.target.selectedIndex].getAttribute('data-option-id');
}
Run Code Online (Sandbox Code Playgroud)
到目前为止这工作正常,但我需要this.optionId
默认设置,所以我必须data-options-id
在渲染上获取第一个选项
我怎样才能做到这一点?
我是 React 和 Mobx 的新手,所以我尝试做一个小应用程序。当我尝试运行它时,我收到错误:Uncaught TypeError: _releasesState2.default is not a constructor
. 因为我不知道问题是什么,所以我要猛烈抨击我的头。这是我到目前为止所得到的:
我的 index.js:
import React from "react";
import ReactDOM from "react-dom";
import Releases from "./components/releases";
class App extends React.Component {
constructor() {
super();
}
render() {
return (
<div>
<Releases />
</div>
)
}
}
ReactDOM.render(<App/>, window.document.getElementById("app"));
Run Code Online (Sandbox Code Playgroud)
release.js:
import React from "react";
import { observer } from "mobx-react";
import ReleaseState from "./releases-state";
@observer
export default class Releases extends React.Component {
constructor() {
super();
this.state = new ReleaseState(); …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个小型应用程序react
,用户可以在其中注册、登录等。对于登录,我创建了一个带有额外错误验证的登录表单,来自后端。现在,当我尝试登录并故意输入错误的凭据时,没有任何反应(出于某种原因是正确的),但控制台告诉我错误消息,而不是我的错误消息:
Failed prop type: Invalid prop `errors` of type `string` supplied to `Login`, expected `object`
Run Code Online (Sandbox Code Playgroud)
这是代码:
import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import classnames from "classnames";
import { loginUser } from "../../actions/authActions";
class Login extends Component {
constructor() {
super();
this.state = {
email: "",
password: "",
errors: {}
};
this.onChange = this.onChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}
componentWillReceiveProps(nextProps) {
if (nextProps.auth.isAuthenticated) {
this.props.history.push("/mysite");
}
if (nextProps.errors) { …
Run Code Online (Sandbox Code Playgroud)