小编Dev*_*wal的帖子

Php 7.1 - 空索引运算符数组

正如http://php.net/manual/en/language.types.array.php中提到的

注意:从 PHP 7.1.0 开始,对字符串应用空索引运算符会引发致命错误。以前,字符串被默默地转换为数组。

有人可以举个例子告诉我这是什么意思吗?

它将如何影响我的代码?

谢谢!

php arrays string error-handling

6
推荐指数
1
解决办法
2310
查看次数

POST文件以及表单数据Vue + axios

我有一个Vuejs组件的方法:

async submit () {
        if (this.$refs.form.validate()) {
          let formData = new FormData()
          formData.append('userImage', this.avatarFile, this.avatarFile.name)
          this.avatarFile = formData
          try {
            let response = await this.$axios.post('http://localhost:3003/api/test.php', {
              avatar: this.avatarFile,
              name: this.name,
              gender: this.gender,
              dob: this.DOB,
            }, {
              headers: {
                'Content-Type': 'multipart/form-data; boundary=' + formData._boundary
              }
            })
            if (response.status === 200 && response.data.status === 'success') {
              console.log(this.response)
            }
          } catch (e) {
           console.log(e)
          }
        }
      }
Run Code Online (Sandbox Code Playgroud)

在中test.php,我json_decode(file_get_contents("php://input"), TRUE);用来读取数据作为$_POST变量。

虽然我能读namegenderdob正确,我不能获取 …

php vue.js vue-component axios nuxt.js

6
推荐指数
1
解决办法
7073
查看次数

MySQL - 获取没有时区偏移的日期

我将比斯 (DOB) 的日期存储为 mySQL 表中的日期列。

现在的问题是:当我插入出生日期时,例如:2001/02/02,我可以毫无问题地存储它。但是当我选择它 ( SELECT dob FROM table1) 时,我会得到 UTC 格式的结果,例如:2001-02-01T18:30:00.000Z

我继续深入挖掘,发现这是因为 UTC 偏移。

有没有办法返回没有UTC偏移量的表中存储的日期?无论UTC如何,所有时区的出生日期都需要保持不变。

注意:我不想更改服务器时区,因为我确实有某些使用时差的列。

编辑:当我使用 MySQL 工作台执行查询时,我得到了预期的结果,但是当我使用 node (mysqljs) 时,我得到了时区格式的结果。

编辑:刚刚发现这是 mysqljs 的问题,因为它使用 timezone 属性连接到 mysql 服务器。( https://github.com/mysqljs/mysql#connection-options )

先感谢您。

mysql database date date-of-birth node.js

3
推荐指数
1
解决办法
2589
查看次数

在foreach循环中使用回调函数

我试图在forEach循环中使用带有回调的函数。

在继续下一步之前,我需要等待执行完成。

这是我的代码:

const arr = '6,7,7,8,8,5,3,5,1'

const id = arr.split(',');

const length = id.length;


id.forEach( (x, index) => {
  (function FnWithCallback () {
    setTimeout(() => { console.log(x) }, 5000);
  })();
});

console.log('done');
Run Code Online (Sandbox Code Playgroud)

我想出了一个办法:

const arr = '6,7,7,8,8,5,3,5,1'

const id = arr.split(',');

const length = id.length;

const fn = () => {
  return new Promise (resolve => {
    id.forEach( (id, index) => {
      setTimeout(() => {console.log(id)}, 3000);

      if(index === (length - 1))
         resolve();
    })
  })
}

fn().then(()=> { …
Run Code Online (Sandbox Code Playgroud)

javascript foreach es6-promise

2
推荐指数
1
解决办法
73
查看次数

导出动态变量

我正在尝试在node.js中导出一个变量,如下所示:

let news = [];

const fetchNews = new Promise ((resolve, reject) => {

  let query = 'SELECT id, name FROM news';

  mysql.query(query, [], (error, results) => {

    if (error)
      reject({error: `DB Error: ${error.code} (${error.sqlState})`})

    results = JSON.parse(JSON.stringify(results));

    news = results;

    resolve(results);

  });

});

if(!news.length)
  fetchNews
    .then(results => {news = results})
    .catch(err => {console.log('Unable to fetch news', err)});

exports.news = news;
Run Code Online (Sandbox Code Playgroud)

当我在其他模块中使用此代码时,如下所示:

const news = require('./news.js').news;

console.log(news);
//returns [];
Run Code Online (Sandbox Code Playgroud)

有人可以在第一段代码中指出我的错误吗?

node.js promise node-modules

0
推荐指数
1
解决办法
216
查看次数