我刚刚擦了我的Mac并重新安装了El Capitan.我现在正努力连接到Mysql.完成Web服务器设置过程后,我创建了一个简单的PHP测试文件:
<?php
  $conn = new mysqli("127.0.0.1", "root", "xxxxxxxx");
  if ($conn->connect_error) echo "Connection failed: " . $conn->connect_error; 
  else echo "Connected successfully";
  phpinfo();
?>
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到此错误:
Warning: mysqli::mysqli(): (HY000/1862): Your password has expired. To log in you must change it using a client that supports expired passwords. in /Users/rich/Documents/DESIGN/test/index.php on line 3
Connection failed: Your password has expired. To log in you must change it using a client that supports expired passwords.
Run Code Online (Sandbox Code Playgroud)
我以前从未见过连接的响应.如果我无法连接,如何解决?
编辑
在终端我输入命令:
mysql -u root -p
这问我输入的密码(当前的密码).我现在可以访问mysql命令,但我尝试的任何内容都会导致此错误:
ERROR 1820 …Run Code Online (Sandbox Code Playgroud) 在我的NodeJS代码中,我需要进行2或3次API调用,每次调用都会返回一些数据.完成所有API调用后,我想将所有数据收集到一个JSON对象中以发送到前端.
我知道如何使用API回调(下一次调用将在前一次调用的回调中发生),但这会很慢:
//1st request
request('http://www.example.com', function (err1, res1, body) {
  //2nd request
  request('http://www.example2.com', function (err2, res2, body2) {
    //combine data and do something with it
  });
});
Run Code Online (Sandbox Code Playgroud)
我知道你也可以做类似的事情并且更符合承诺,但我认为同样的概念适用于下一个调用在当前调用完成之前不会执行的情况.
有没有办法同时调用所有函数,但是我的最后一段代码是等待所有API调用完成并在执行之前提供数据?
我试图在多个部分中找到输入值的总和.我把我的代码放到了下面.
HTML:
<div class="section">
  <input type="radio" name="q1" value="2"/>
  <input type="radio" name="q2" value="0"/>
  <input type="radio" name="q3" value="1"/>
  <input type="radio" name="q4" value="3"/>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery:
$('.section').each(function(){
  var totalPoints = 0;
  $(this).find('input').each(function(){
    totalPoints += $(this).val();
  });
  alert(totalPoints);
});
Run Code Online (Sandbox Code Playgroud)
请注意,这是我实际使用的代码的简化版本.所以我希望这可以提醒2个值(每个部分的总和):8然后6.相反,我只是获取所有值的字符串.所以第一部分警告0143.
有什么想法我如何获得累积总和而不是字符串?
目前正在将我的项目转换为使用 Typescript。我以前在 Node 中启动 Express 的工作代码如下所示:
server.listen(port, (error) => {
  if (error) throw error;
  console.info(`Ready on port ${port}`);
});
Run Code Online (Sandbox Code Playgroud)
有了这个,我现在得到一个打字稿错误:
Argument of type '(error: any) => void' is not assignable to parameter of type '() => void'.
Run Code Online (Sandbox Code Playgroud)
我试过为参数分配一个类型,例如error: Errororerror: any但这并不能解决问题。我在这里做错了什么?
另外,由于我是 Typescript 的新手,虽然我已经找到了大量通常用于学习 Typescript 的资源,但是否有任何地方我应该知道如何在更特定于 npm 包的场景中处理 Typescript?
我的 Typescript 项目中有一个有状态的 React 组件。我使用 ESLint@typescript-eslint/parser和lint 它@typescript-eslint/eslint-plugin。我已经启用了规则@typescript-eslint/explicit-function-return-type。
我的组件看起来类似于:
interface Props = {
  name: string;
}
interface State = {
  score: number
}
class Person extends Component<Props, State> {
  state = {
    score: 2,
  };
  componentDidMount() {
    ...
  }
  render() {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)
在上面的组件中,我在componentDidMount和render方法上得到了 ESLint 错误:
Missing return type on function - @typescript-eslint/explicit-function-return-type
总的来说,我非常喜欢 lint 规则,但我肯定不必为所有这些 React 方法声明返回类型。我已经安装@types/react并@types/react-dom安装了,所以这些返回类型不是已经涵盖了吗?
我有以下简单的 NodeJS 代码:
const express = require('express');
const server: express.Application = express();
Run Code Online (Sandbox Code Playgroud)
我正在将 Typescript 添加到我的项目中并且是新手,所以请原谅我。使用上面的代码,我得到以下问题/错误:
对于要求:
var require: NodeRequire (id: string) => any (+1 overload)
'require' call may be converted to an import.
Run Code Online (Sandbox Code Playgroud)
对于 express.Application 用法:
Cannot find namespace 'express'.
Run Code Online (Sandbox Code Playgroud)
如果我将“require”切换为“import”,它会修复命名空间错误,但不再是有效的节点代码,因此不会运行(引发有关导入的意外令牌的新错误)。
使用 Typescript 编写这样的 Node 代码以避免这些错误的正确方法是什么?
我的 tsconfig.json 看起来像这样:
{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "preserve",
    "lib": ["dom", "es2017"],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": …Run Code Online (Sandbox Code Playgroud) 我有一个 NextJS React 应用程序,它使用 next-react-wrapper(基本上是一个 HOC),_app.tsx如下所示:
_app.tsx
...
import withRedux from 'next-redux-wrapper';
class Page extends App<Props> {
  ...
}
export default withRedux(reduxStore)(Page);
Run Code Online (Sandbox Code Playgroud)
store.ts
import { applyMiddleware, createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
import rootReducer from './reducer';
export default (
  initialState: any = undefined,
) => createStore(
  rootReducer,
  initialState,
  composeWithDevTools(applyMiddleware()),
);
Run Code Online (Sandbox Code Playgroud)
我正在努力研究如何在 React 之外访问商店,例如在一个简单的辅助函数中。我的store.ts文件导出了makeStorenext-redux-wrapper HOC 所需的函数(包括初始状态)。
我可以在 React 组件中访问 store 并将其作为参数每次传递给我的辅助函数,但这看起来很混乱。
有没有办法直接从非 React 辅助功能模块访问商店?
我有一些像这样的HTML:
<div class="slide">
  <a href="#" class="test">Test</a>
</div>
<div class="other">
  ...
</div>
<div class="slide">
  <a href="#" class="test">Test</a>
</div>
<div class="other">
  ...
</div>
Run Code Online (Sandbox Code Playgroud)
现在,当我点击其中一个测试链接时,我想得到父div的索引.但是,我希望索引只是div.slide元素.
我尝试过以下方法:
$('a.test').click(function(){
  var slideIndex = $(this).parents('.slide').index();
  alert(slideIndex);
});
Run Code Online (Sandbox Code Playgroud)
以上警告0表示第一个链接,2表示第二个链接.我希望它为第二个链接提醒1,因为它是第二个链接div.slide.我怎样才能改变我为此做的事情?
在研究如何为网页面包屑做微数据时,我发现了几种方法,我不确定哪种方法是正确的.首先,我在HTML中的基本面包屑看起来像这样:
<div>
  <a href="/">Root page</a>
  <a href="/category">Category page</a>
  <a href="/category/this-page">This page</a>
</div>
Run Code Online (Sandbox Code Playgroud)
现在,我是否像这样构建它(正如我在SchemaOrg的示例中看到的那样:
<ol itemscope itemtype="http://schema.org/BreadcrumbList">
  <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
    <a href="/" itemprop="item">
      <span itemprop="name">Root page</span>
    </a>
  </li>
  <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
    <a href="/category" itemprop="item">
      <span itemprop="name">Category page</span>
    </a>
  </li>
  <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
    <a href="/category/this-page" itemprop="item">
      <span itemprop="name">This page</span>
    </a>
  </li>
</ol>
Run Code Online (Sandbox Code Playgroud)
或者像我在Stackoverflow的一些答案中看到的那样构造它如下所示:
<div>
  <span itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
    <a href="/" itemprop="url">
      <span itemprop="title">Root page</span>
    </a>
  </span>
  <span itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
    <a href="/category" itemprop="url">
      <span itemprop="title">Category …Run Code Online (Sandbox Code Playgroud) 我有一个无状态的功能组件,它没有道具并从 React 上下文填充内容。作为参考,我的应用程序使用 NextJS 并且是一个同构应用程序。我第一次尝试在这个组件上使用 React.memo() 但它会在客户端页面更改时不断重新渲染,尽管道具和上下文没有改变。由于我放置了控制台日志,我知道这一点。
我的组件的一个简短示例是:
const Footer = React.memo(() => {
  const globalSettings = useContext(GlobalSettingsContext);
  console.log('Should only see this once');
  return (
    <div>
      {globalSettings.footerTitle}
    </div>
  );
});
Run Code Online (Sandbox Code Playgroud)
我什至尝试过在没有运气的情况下传递第二个参数:
const Footer = React.memo(() => {
  ...
}, () => true);
Run Code Online (Sandbox Code Playgroud)
任何想法这里出了什么问题?
编辑:上下文提供程序的用法_app.js如下所示:
class MyApp extends App {
  static async getInitialProps({ Component, ctx }) {
    ...
    return { globalSettings };
  }
  render() {    
    return (
      <Container>
        <GlobalSettingsProvider settings={this.props.globalSettings}>
          ...
        </GlobalSettingsProvider>
      </Container>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)
实际的 GlobalSettingsContext 文件如下所示: …