我开始使用react-router v4.<Router>我的app.js中有一个简单的导航链接(参见下面的代码).如果我导航到localhost/vocabulary,路由器会将我重定向到正确的页面.但是,当我按下重新加载(F5)之后(localhost/vocabulary)时,所有内容都会消失并且浏览器报告Cannot GET /vocabulary.怎么可能?有人能给我任何线索如何解决(正确重新加载页面)?
App.js:
import React from 'react'
import ReactDOM from 'react-dom'
import { BrowserRouter as Router, Route, Link } from 'react-router-dom'
import { Switch, Redirect } from 'react-router'
import Login from './pages/Login'
import Vocabulary from './pages/Vocabulary'
const appContainer = document.getElementById('app')
ReactDOM.render(
<Router>
<div>
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/vocabulary">Vocabulary</Link></li>
</ul>
<Switch>
<Route exact path="/" component={Login} />
<Route exact path="/vocabulary" component={Vocabulary} />
</Switch>
</div>
</Router>,
appContainer)
Run Code Online (Sandbox Code Playgroud) 我已经开始在后端使用firebase(Firebase for web)了.我可以很好地处理Firebase实时数据库,但我不清楚Firebase存储(图像,视频等)的工作原理.
基本上我想在我的网站上有一些新闻列表,每个项目都有一些小图片.所以我将这些图片上传到Firebase存储,但是如何访问他们的URL(我的<img/>src属性需要它)?
我开始使用ES6胖箭头功能表示法,我非常喜欢它.但我对它的背景有点困惑.据我所知,关键字this fat arrow函数指的是函数当前运行的上下文.我想做一些简单的jQuery迭代,如:
$('ul#mylist > li').each(() => {
$(this).addClass('some-class-name');
});
Run Code Online (Sandbox Code Playgroud)
但显然这段代码不起作用.如何在胖箭头函数中引用此特定代码中的当前"LI"元素?
可以问一下你吗?如何在jQuery的.css()方法中设置负边距(或其他任何值)?我正在按变量添加尺寸,但是不起作用
var width = $('.gallery div img').outerWidth(true);
$('.gallery').css('margin-left', '- ' + width + 'px');
Run Code Online (Sandbox Code Playgroud)
还是有什么方法可以转换var width为负数?
有什么方法可以找出我的数据何时使用push()方法保存在数据库中?我写了下面的代码,但它多次保存数据......
db.ref('news').push(opts).then(() => {
// do smth. (e.g. hide preloader) when data were succesfully saved
})
Run Code Online (Sandbox Code Playgroud) 我是Firebase的新手,现在我正在努力使用它的文档2个小时,我无法弄清楚如何使用Firebase(Firebase for web)运行我的本地项目.
我的应用程序如下:
-- node_modules
-- app
-- index.html
-- src
-- css, js, etc.
Run Code Online (Sandbox Code Playgroud)
基本上我想从app/index.html运行我的应用程序.我已经安装firebase tools,运行firebase init(我不熟悉所有init选项)然后运行firebase serve.
它抛出错误"发生意外错误",可能是由于缺少公共目录(但我不希望在我的应用程序中有任何"公共"目录).
我还将firebase项目中的firebase应用程序代码放到我的index.html中,但它记录了错误:Error: Illegal url for new iframe和This domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.
firebase ×3
javascript ×3
callback ×1
ecmascript-6 ×1
jquery ×1
localhost ×1
margin ×1
push ×1
react-router ×1
reactjs ×1
routes ×1
width ×1