鍍金池/ 問答/ HTML問答
我不懂 回答

jQuery.post默認(rèn)的Content-Type是application/x-www-form-urlencoded,而你的是application/json

還是不行的話請查看 http://blog.csdn.net/hemingwa...

心上人 回答

今天剛剛補(bǔ)充了知識:廣播模式中交換器會將消息發(fā)到所有綁定到它上面的隊列中。

獨(dú)白 回答

檢查下字符串是否包含特定標(biāo)簽字段如<html>

舊城人 回答

不知道你用的什么框架 我用vue,把websocket對象存vuex就行

話寡 回答

1,一般服務(wù)器寫日志都是有一個buffer的,先寫buffer,buffer寫完了再刷盤,不然磁盤受不了,你多刷個幾十次,看看日志會不會寫進(jìn)去,或者reload下。
2,都是訪問日志,只是 host.access.log 是你定義的 site.com 的server域下的訪問日志,access.log 你定義在了http下面,就是所有的server默認(rèn)的訪問日志文件。 server下的配置會優(yōu)先于http下的配置。

朽鹿 回答

https://segmentfault.com/q/10... 這篇文章里寫的方法可以實(shí)現(xiàn),但是初次加載失敗的問題好像一直都有,用了setTimeout,時而可用,時而不可用。

網(wǎng)妓 回答

Promise適合做一些順序執(zhí)行的事情,簡單來說就是適合完成一個事件后再去執(zhí)行另外一件事情(并不單指執(zhí)行下一個then).如果要進(jìn)行帶容錯處理的鏈?zhǔn)秸{(diào)用,例如判斷一個文件是否存在,then部分和catch部分執(zhí)行代碼不一樣,則必須保證then和catch返回的Promise也是相同的,不然下一個then中必須判斷執(zhí)行的是哪個分支才可以執(zhí)行相應(yīng)的代碼.這會變得十分繁瑣而且也偏離我們使用Promise的本意.

實(shí)際上對于一個問題的結(jié)果,例如操作一個文件,我們只關(guān)心其結(jié)果,完成或者沒有完成.但是獲取這個結(jié)果需要很多個步驟,每個步驟都是有可能出錯的,而且出錯也有相應(yīng)的修復(fù)邏輯

/**
 * 判斷一個文件是否存在
 *    存在            不存在
 *    打開             創(chuàng)建
 * 讀取  打不開     打開   創(chuàng)建不了
 *        報錯              報錯  (假設(shè)到這一層就不執(zhí)行操作了)
 */

完成上面的邏輯,單純用Promise來寫,將會變得十分繁瑣,保證Promise最后一個then或者catch是我們要的結(jié)果下,
任何比正常邏輯多出的分支必須在一個then或者catch里寫完才可以保證最后的結(jié)果只有一個,例如上面部分邏輯的偽代碼

            hasfile.then(()=>{
                //返回不同效果的Promise,并且包含flag
            let Pro=new Promise(/*對應(yīng)后續(xù)打開文件的代碼*/);
                return {
                    hasfile:true,
                    pro:pro
                }
            }).catch(()=>{
                let Pro=new Promise(/*對應(yīng)后續(xù)創(chuàng)建文件的代碼*/);
                return {
                    hasfile:false,
                    pro:pro
                }
            }).then((result)=>{
                //這個時候執(zhí)行的Promise是不一樣的
                if(result.flag){
                    //如果還想繼續(xù)鏈?zhǔn)秸{(diào)用
                    //只能繼續(xù)包裝一個Promise對象并返回
                    //如果直接把result.pro的Promise執(zhí)行,那么鏈?zhǔn)秸{(diào)用就到此結(jié)束
                    
                    return new Promise((resolve,reject)=>{
                        //這里執(zhí)行的是打開的代碼,但是代碼本體卻是在上一個
                        //then里寫的
                        result.then((file)=>{
                            resolve(file);
                        }).catch((err)=>{
                            reject(err)
                        })
                    })
                }else{
                    
                }
            })

結(jié)果就是,Promise不適合干帶有過多邏輯分支或者循環(huán)的異步,不然要Generator和async干嘛

夏木 回答

第一個問題你看你打印的結(jié)果
第一個是[]空數(shù)組 第二個是[{}]數(shù)組包含一個對象 第三個是[{},{}]包含兩個對象,
但你點(diǎn)擊的時候點(diǎn)的是newlist對象的引用,及指向內(nèi)存區(qū)域的值,因?yàn)槟愕姆椒▓?zhí)行完了所以打開都是包含兩個對象,你可以運(yùn)行一下下面的代碼看一下,第二個問題同第一個問題

var list = [{name:"xiaoming",age:12},{name:"xiaohong",age:13},{name:"dondong",age:15}];
var newlist = [];
for(var i = 0;i<list.length;i++){
    if(parseInt(list[i].age) !== 12){
        newlist.push(list[i]);
    }
    console.log(JSON.stringify(newlist));   
}
兮顏 回答

可以微信開發(fā)者工具中查看獲得權(quán)限,是否真的配置是有效的

clipboard.png

替身 回答

initialValue

clipboard.png

咕嚕嚕 回答

你在{"comments":{"$slice":1}這個外面套一層 projection 就可以了。
最終變成findOne({ "_id": ObjectId(user_id)},{projection: {"comments":{"$slice":1}}}

抱緊我 回答
  • 試了網(wǎng)上幾個方法都不管用,于是我直接簡單粗暴的把 webpack.prod.conf.js 中的 兩處
  • CommonsChunkPlugin注釋掉了。就沒報錯,目前沒問題。
  • 下面把代碼放一下
var path = require('path')
var utils = require('./utils')
var webpack = require('webpack')
var config = require('../config')
var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf')
var CopyWebpackPlugin = require('copy-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')

var env = config.build.env

var webpackConfig = merge(baseWebpackConfig, {
  module: {
    rules: utils.styleLoaders({
      sourceMap: config.build.productionSourceMap,
      extract: true
    })
  },
  devtool: config.build.productionSourceMap ? '#source-map' : false,
  output: {
    path: config.build.assetsRoot,
    filename: utils.assetsPath('js/[name].[chunkhash].js', true),
    chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
  },
  plugins: [
    // http://vuejs.github.io/vue-loader/en/workflow/production.html
    new webpack.DefinePlugin({
      'process.env': env
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      },
      sourceMap: true
    }),
    // extract css into its own file
    new ExtractTextPlugin({
      filename: utils.assetsPath('css/[name].[contenthash].css', true),
      allChunks: true
    }),
    // Compress extracted CSS. We are using this plugin so that possible
    // duplicated CSS from different components can be deduped.
    new OptimizeCSSPlugin({
      cssProcessorOptions: {
        safe: true
      }
    }),
    // generate dist index.html with correct asset hash for caching.
    // you can customize output by editing /index.html
    // see https://github.com/ampedandwired/html-webpack-plugin
    ...utils.getHtmlPlugins(),
    // keep module.id stable when vender modules does not change
    new webpack.HashedModuleIdsPlugin(),
    // split vendor js into its own file
     <1.--------------------------------------------------------------------->
    // new webpack.optimize.CommonsChunkPlugin({
    //   name: 'vendor',
    //   minChunks: function (module, count) {
    //     // any required modules inside node_modules are extracted to vendor
    //     return (
    //       module.resource &&
    //       /\.js$/.test(module.resource) &&
    //       module.resource.indexOf(
    //         path.join(__dirname, '../node_modules')
    //       ) === 0
    //     )
    //   }
    // }),
     ----------------------------------------------------------------------
    // extract webpack runtime and module manifest to its own file in order to
    // prevent vendor hash from being updated whenever app bundle is updated
     <2.--------------------------------------------------------------------->
    // new webpack.optimize.CommonsChunkPlugin({
    //   name: 'manifest',
    //   chunks: ['vendor']
    // }),
     ----------------------------------------------------------------------
    // copy custom static assets
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, '../static'),
        to: config.build.assetsSubDirectory,
        ignore: ['.*']
      }
    ])
  ]
})

if (config.build.productionGzip) {
  var CompressionWebpackPlugin = require('compression-webpack-plugin')

  webpackConfig.plugins.push(
    new CompressionWebpackPlugin({
      asset: '[path].gz[query]',
      algorithm: 'gzip',
      test: new RegExp(
        '\\.(' +
        config.build.productionGzipExtensions.join('|') +
        ')$'
      ),
      threshold: 10240,
      minRatio: 0.8
    })
  )
}

if (config.build.bundleAnalyzerReport) {
  var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  webpackConfig.plugins.push(new BundleAnalyzerPlugin())
}

module.exports = webpackConfig
北城荒 回答

@歐兜兜是素姀 的回答是正確的,mongoose的Schema可以使用required屬性來規(guī)范數(shù)據(jù),這樣不符合要求的數(shù)據(jù)存入mongodb會失敗的。

但是,就算是數(shù)據(jù)庫規(guī)范了,前端也不能假設(shè)數(shù)據(jù)庫返回的數(shù)據(jù)沒問題,前端還是需要對后端返回的數(shù)據(jù)進(jìn)行驗(yàn)證和容錯。因?yàn)榍岸撕秃蠖耸欠蛛x的,前端需要假設(shè)后端會出錯。事實(shí)上,后端出錯也是無法避免的,因?yàn)榇a一直在修改,哪天后端不小心刪掉required字段呢?

你這是微信開發(fā),去微信開發(fā)者中心找找文檔,另外這種涉及隱私的行為估計不能正常獲取

終相守 回答

不可以,要么把數(shù)組提到外面去定義,要么在定義obj之后再賦值key5

失魂人 回答

React.PureComponent  其實(shí)是重寫了SCU(shouldComponentUpdate)方法。

React.Component shouldComponentUpdate 的實(shí)現(xiàn)是直接返回true。

這就是兩者的區(qū)別。 造成這樣的情況的原因就在于shouldComponentUpdate”錯誤“地將返回值變成false了。

PureComponent 重寫的SCU其實(shí)就是shallow equal 兩個state和nextState,prop和nextProps。

從你的代碼中看,是

let nextIndex=++preState.index; 
// 等價于

let nextIndex = preState = preState.index + 1;

因此不僅僅修改了nextIndex, 同時也修改了preState.index.

你可以繼承React.Component,自己寫SCU,然后debug看一下就明白了。

希望我的回答對你有幫助。

哎呦喂 回答
  1. 打開 HOSTS 文件,添加:

      127.0.0.1 你的api所在的域名
  2. 打開 phpstudy 打開“站點(diǎn)域名管理”,配置一個本地域名,也就是你的api所在的域名
  3. 打開微信開發(fā)者工具,右側(cè)的“詳情”,選擇: 不校驗(yàn)合法域名、web-view(業(yè)務(wù)域名)、TLS 版本以及 HTTPS 證書
  4. 如果你原來請求的 url 中是 https 的,請暫時先把 改成 http 。

這時,如果你的 php代碼已經(jīng)實(shí)現(xiàn)的接口的功能,就應(yīng)該可以正常測試了。