Javascript Nextjs使用样式化jsx反应SSR-无法读取属性';州';未定义的
我偶然发现了一个我似乎无法解决的问题。我试图在这里寻找解决办法,但无法控制自己。我是javascript的新手,所以要考虑周到 问题: 我正在使用React(16.5.0)和nextjs(6.1.2)以及样式化jsx,如下所示:Javascript Nextjs使用样式化jsx反应SSR-无法读取属性';州';未定义的,javascript,reactjs,next.js,Javascript,Reactjs,Next.js,我偶然发现了一个我似乎无法解决的问题。我试图在这里寻找解决办法,但无法控制自己。我是javascript的新手,所以要考虑周到 问题: 我正在使用React(16.5.0)和nextjs(6.1.2)以及样式化jsx,如下所示: import React, {Component} from 'react'; import PropTypes from 'prop-types'; import Link from 'next/link'; class ProductCard extends Co
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import Link from 'next/link';
class ProductCard extends Component {
constructor(props) {
super(props);
this.state = {imgLoaded: false};
this.imgHasLoaded = this.imgHasLoaded.bind(this);
}
imgHasLoaded() {
this.setState({imgLoaded:true})
}
render() {
return (
<div className="thumbnail-container">
<div className="loader-box">
<img src={require("../static/loading.png")} className="loading-img" />
</div>
<img src={this.props.imgSrc} className="main-img" onLoad={this.imgHasLoaded} />
<div className="thumbnail-text">
{this.props.text}
</div>
<ul className="item-list">
{this.props.links.map(link =>
<li className="item">
<span className="item-span"> {link.text} </span>
{link.subLinks &&
<ul className="sub-item-list">
{link.subLinks.map(subLink => <li>{subLink.text}</li>)}
</ul>
}
</li>
)}
</ul>
<style jsx> {`
.thumbnail-container {
user-select: none;
position: relative;
text-align: center;
width: 98%;
height: 98%;
margin: 1%;
display: block;
border: 0.3px solid black;
overflow: hidden;
border-radius: 10px;
box-shadow: 0 0 20px 0px rgba(0, 0, 0, 0.5);
overflow: hidden;
align-items: center;
}
.thumbnail-text {
position: absolute;
width: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #ffffff;
font-size: 1.8em;
background-color: #333;
padding: 5px;
border-radius: 5px;
text-shadow: 1px 1px #000000;
text-transform: uppercase;
box-shadow: 0 5px 10px 0px rgba(0, 0, 0, 1);
transition: all 0.2s ease;
}
.thumbnail-container:hover .thumbnail-text, .thumbnail-container:focus .thumbnail-text, .thumbnail-container:active .thumbnail-text {
top: 0;
transform: translate(-50%, 0);
background-color: rgba(255, 124, 4, 0.9);
color: #000000;
text-shadow: none;
}
.main-img {
width: 100%;
height: 100%;
border-radius: 8px;
margin: auto;
-webkit-filter: grayscale(40%) contrast(120%) brightness(110%) saturate(120%);
-moz-filter: grayscale(40%) contrast(120%) brightness(110%) saturate(120%);
filter: grayscale(40%) contrast(120%) brightness(110%) saturate(120%);
opacity: ${this.state.imgLoaded ? 1 : 0};
}
.thumbnail-container:hover .main-img, .thumbnail-container:focus .main-img, .thumbnail-container:active .main-img{
-webkit-filter: grayscale(40%) contrast(120%) saturate(120%) brightness(30%);
-moz-filter: grayscale(40%) contrast(120%) saturate(120%) brightness(30%);
filter: grayscale(40%) contrast(120%) saturate(120%) brightness(30%);
}
.item-list {
display: none;
position: absolute;
bottom: 0;
left: 0;
height: calc(100% - 2em);
flex-flow: column wrap;
justify-content: space-around;
list-style-type: none;
}
.thumbnail-container:hover .item-list, .thumbnail-container:focus .item-list, .thumbnail-container:active .item-list{
display: flex;
}
.item {
font-size: 1.3em;
display: flex;
flex-flow: column wrap;
}
.item-span {
padding-left: 8px;
border-bottom: solid #ff7c04;
border-left: solid #ff7c04;
transition: border-bottom 0.2s ease;
}
.item:hover .item-span, .item:focus .item-span, .item:active .item-span{
border-bottom: none;
}
.sub-item-list {
margin-left: 8px;
margin-top: 8px;
border-bottom: solid #ff7c04;
border-left: solid #ff7c04;
height: auto;
flex: 0;
overflow: hidden;
transition: flex 0.2s ease;
}
.item:hover .sub-item-list, .item:focus .sub-item-list, .item:active .sub-item-list{
flex: 1;
}
.loader-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 48px;
height: 48px;
}
.loading-img {
-webkit-animation: rotate-scale-up 1s linear infinite both;
animation: rotate-scale-up 1s linear infinite both;
}
@-webkit-keyframes rotate-scale-up {
0% {
-webkit-transform: scale(1) rotateZ(0);
transform: scale(1) rotateZ(0);
}
50% {
-webkit-transform: scale(1.5) rotateZ(180deg);
transform: scale(1.5) rotateZ(180deg);
}
100% {
-webkit-transform: scale(1) rotateZ(360deg);
transform: scale(1) rotateZ(360deg);
}
}
@keyframes rotate-scale-up {
0% {
-webkit-transform: scale(1) rotateZ(0);
transform: scale(1) rotateZ(0);
}
50% {
-webkit-transform: scale(1.5) rotateZ(180deg);
transform: scale(1.5) rotateZ(180deg);
}
100% {
-webkit-transform: scale(1) rotateZ(360deg);
transform: scale(1) rotateZ(360deg);
}
}
a {
text-decoration: none;
}
@media only screen and (max-width: 700px) {
.thumbnail-container {
width: 96%;
height: 96%;
margin: 2%;
}
.thumbnail-text {
height: 1.5em;
font-size: 1em !important;
}
.item-list {
height: calc(100% - 3em) !important;
}
}
`}
</style>
</div>
);
}
}
import React,{Component}来自'React';
从“道具类型”导入道具类型;
从“下一个/链接”导入链接;
类ProductCard扩展组件{
建造师(道具){
超级(道具);
this.state={imgLoaded:false};
this.imgHasLoaded=this.imgHasLoaded.bind(this);
}
imgHasLoaded(){
this.setState({imgLoaded:true})
}
render(){
返回(
{this.props.text}
{this.props.links.map(link=>
-
{link.text}
{link.subLinks&&
{link.subLinks.map(subLink=>- {subLink.text}
)}
}
)}
{`
.缩略图容器{
用户选择:无;
位置:相对位置;
文本对齐:居中;
宽度:98%;
身高:98%;
利润率:1%;
显示:块;
边框:0.3倍纯黑;
溢出:隐藏;
边界半径:10px;
盒影:0 0 20px 0 px rgba(0,0,0,0.5);
溢出:隐藏;
对齐项目:居中;
}
.缩略文本{
位置:绝对位置;
宽度:100%;
最高:50%;
左:50%;
转换:翻译(-50%,-50%);
颜色:#ffffff;
字号:1.8em;
背景色:#333;
填充物:5px;
边界半径:5px;
文本阴影:1px 1px#000000;
文本转换:大写;
盒影:0 5px 10px 0px rgba(0,0,0,1);
过渡:所有0.2秒缓解;
}
.缩略图容器:悬停。缩略图文本。缩略图容器:焦点。缩略图文本。缩略图容器:活动。缩略图文本{
排名:0;
转换:转换(-50%,0);
背景色:rgba(255,124,4,0.9);
颜色:#000000;
文本阴影:无;
}
.主img{
宽度:100%;
身高:100%;
边界半径:8px;
保证金:自动;
-webkit过滤器:灰度(40%)对比度(120%)亮度(110%)饱和(120%);
-莫兹滤波器:灰度(40%)对比度(120%)亮度(110%)饱和(120%);
滤镜:灰度(40%)对比度(120%)亮度(110%)饱和(120%);
不透明度:${this.state.imgLoaded?1:0};
}
.缩略图容器:悬停。主img。缩略图容器:焦点。主img。缩略图容器:活动。主img{
-webkit过滤器:灰度(40%)对比度(120%)饱和(120%)亮度(30%);
-莫兹滤波器:灰度(40%)对比度(120%)饱和(120%)亮度(30%);
滤镜:灰度(40%)对比度(120%)饱和(120%)亮度(30%);
}
.项目清单{
显示:无;
位置:绝对位置;
底部:0;
左:0;
高度:计算(100%-2米);
柔性流:柱包裹;
证明内容:周围的空间;
列表样式类型:无;
}
.缩略图容器:悬停。项目列表。缩略图容器:焦点。项目列表。缩略图容器:活动。项目列表{
显示器:flex;
}
.项目{
字体大小:1.3em;
显示器:flex;
柔性流:柱包裹;
}
.项目跨度{
左侧填充:8px;
边框底部:实心#ff7c04;
左边框:实心#ff7c04;
过渡:边界底部0.2s;
}
.item:hover.item span、.item:focus.item span、.item:active.item span{
边框底部:无;
}
.分项清单{
左边距:8px;
边缘顶部:8px;
边框底部:实心#ff7c04;
左边框:实心#ff7c04;
高度:自动;
弹性:0;
溢出:隐藏;
过渡:flex 0.2s易用性;
}
.item:hover.sub-item list、.item:focus.sub-item list、.item:active.sub-item-