小编Ani*_*t3d的帖子

Screeps:计算身体的构建成本

在玩游戏screeps.com时,我想计算构建所需身体的成本.请参阅下面的我的尝试,cfg.bodybodypart数组在哪里,例如[Game.ATTACK, Game.MOVE, Game.WORK, Game.CARRY, Game.MOVE]:

var buildCost = 0;

for(var bodypart in cfg.body){
  switch(bodypart){
    case "MOVE":
    case "CARRY":
       buildCost+=50;
       break;
    case "WORK":
       buildCost+=20;
       break;
    case "HEAL":
       buildCost+=200;
       break;
    case "TOUGH":
       buildCost+=20;
       break;
    case "ATTACK":
       buildCost+=80;
       break;
    case "RANGED_ATTACK":
       buildCost+=150;
       break;
  }
  console.log(bodypart + " costs " + buildCost);
}
Run Code Online (Sandbox Code Playgroud)

打印bodypart到控制台时,它显示索引(0,1,2,3,...),buildCost保持为0.

成本和零件在Screeps页面上描述.

javascript screeps

13
推荐指数
3
解决办法
5275
查看次数

[Vue警告]:未知的自定义元素:<nuxt-link>-运行Jest单元测试时

问题

我使用nuxt 1.4,并使用Jest进行路由以进行单元测试。我的应用程序不会抛出错误,并且看起来运行良好。但是,当运行我的单元测试npm run unit(运行笑话)时,它将在终端中引发错误:[Vue warn]: Unknown custom element: <nuxt-link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

预期

我希望它不会引发此错误,因为我的应用程序正在运行。

档案

package.json

{
  "name": "vue-starter",
  "version": "1.0.0",
  "description": "Nuxt.js project",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "precommit": "npm run lint",
    "test": "npm run lint && npm run unit",
    "unit": "jest",
    "unit:report": …
Run Code Online (Sandbox Code Playgroud)

vue.js jestjs vue-router nuxt.js vue-test-utils

8
推荐指数
2
解决办法
3743
查看次数

在dc.js/Crossfilter中添加过滤器而不更新图表

jsFiddle:http: //jsfiddle.net/PYeFP/

我有一个条形图设置,用于显示用户白天的行程数

        tripVolume = dc.barChart("#trip-volume")
               .width(980) // (optional) define chart width, :default = 200
               .height(75) // (optional) define chart height, :default = 200
               .transitionDuration(0) // (optional) define chart transition duration, :default = 500
               .margins({ top: 10, right: 50, bottom: 30, left: 40 })
               .dimension(tripsByDateDimension) // set dimension
               .group(tripsByDateGroup) // set group
               // (optional) whether chart should rescale y axis to fit data, :default = false
               .elasticY(false)
               // (optional) whether chart should rescale x axis to fit data, …
Run Code Online (Sandbox Code Playgroud)

d3.js crossfilter dc.js

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

使用vuelidate验证嵌套对象时,在vuetify中显示错误消息

我正在使用vuelidate验证我的表单输入并使用vuetifyjs显示错误消息。我设法进行了基本的对象验证,并能够显示错误消息。

但是,当我验证集合时,在显示错误消息时遇到了问题。

问题

数据结构示例:

contact: {
  websites: [
    {
      url: 'http://www.something.com',
      label: 'Website',
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

验证示例:

validations: {
  websites: {
    $each: {
      url: {
        url,
      }
    }
  },
}
Run Code Online (Sandbox Code Playgroud)

示例模板:

<template v-for="(website, index) in websites">
        <v-layout row :key="`website${index}`">
          <v-flex xs12 sm9 class="pr-3">
            <v-text-field
                    label="Website"
                    :value="website.url"
                    @input="$v.websites.$touch()"
                    @blur="$v.websites.$touch()"
                    :error-messages="websiteErrors"
            ></v-text-field>
          </v-flex>
        </v-layout>
</template>
Run Code Online (Sandbox Code Playgroud)

计算错误消息示例:

websiteErrors() {
        console.log('websites',this.$v.websites) // contains $each
        const errors = []
        if (!this.$v.websites.$dirty) {
          return errors
        }
        // Issue is that all of …
Run Code Online (Sandbox Code Playgroud)

validation vuejs2 vuetify.js vuelidate

4
推荐指数
1
解决办法
1万
查看次数