小编Art*_*sow的帖子

Node.js检查存在文件

我如何检查文件的存在?

在该模块的文档中,fs有一个方法的描述fs.exists(path, callback).但是,据我所知,它检查是否只存在目录.我需要检查文件!

如何才能做到这一点?

fs node.js

129
推荐指数
11
解决办法
19万
查看次数

模板格式错误:未解决的资源依赖关系

我尝试使用以下模板创建一个 EC2 实例:

Parameters:
  KeyName:
    Default: TestKeyPair
    Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
    Type: AWS::EC2::KeyPair::KeyName
Resources:
  Dev:
    Properties:
      ImageId: ami-4e79ed36
      InstanceType: t2.micro
      KeyName: !Ref 'KeyName'
      SecurityGroups:
        - !Ref 'SSH'
    Type: AWS::EC2::Instance
Run Code Online (Sandbox Code Playgroud)

但我得到:

An error occurred (ValidationError) when calling the CreateChangeSet operation: Template format error: Unresolved resource dependencies [SSH] in the Resources block of the template
Run Code Online (Sandbox Code Playgroud)

我无法理解模板中有什么问题,因为名为“SSH”的安全组已经存在:

$ aws ec2 describe-security-groups --group-names SSH
....
"IpPermissions": [
    {
        "ToPort": 22,
        "IpRanges": [
            {
                "CidrIp": …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-cloudformation

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

如何使用 eslint 在所有导入中强制使用 .vue 扩展名?

在带有Vetur 的VS Code (使用 Vue 的扩展)中,“转到定义”不适.vue用于最后没有扩展的组件导入(Vetur FAQ 链接

我想知道是否有 eslint 规则会强制用户import.vue文件中使用语句时始终提供扩展名?

例子:

  • ?? 这有效:

      import HelloWorld from '@/components/HelloWorld.vue'
    
    Run Code Online (Sandbox Code Playgroud)

    在 VS Code 中右键单击HelloWorld并按下将Go to definition带您到该HelloWorld.vue文件。

  • ? 这不会:

    import HelloWorld from '@/components/HelloWorld'
    
    Run Code Online (Sandbox Code Playgroud)

    如果按Go to definitionHelloWorld(最左边),VS代码只会将光标移动到HelloWorld你恰到好处点击。预期行为是我们移动到HelloWorld.vue文件。

eslint vue.js vetur

6
推荐指数
2
解决办法
3222
查看次数

Koa + TypeScript:请求类型上不存在属性“body”

我想将 koa & koa-bodyparser 与 TypesScript 一起使用,但是每当我访问时,我都会收到一个类型上不存在的错误ctx.request.bodybodyRequest

import Koa from 'koa'
import Router from 'koa-router'
import bodyparser from 'koa-bodyparser'

const app = new Koa()
const router = new Router()

const data = ['lorem', 'ipsum', 'dolor', 'sit', 'amet']

app.use(bodyparser())
router.post('/', (ctx, next) => {
  const phrase = ctx.request.body; // Property 'body' does not exist on type Request
  if (typeof phrase === 'string') {
    ctx.response.body = data.filter(element => element.includes(phrase))
  }
})
Run Code Online (Sandbox Code Playgroud)

typescript koa koa-bodyparser

5
推荐指数
1
解决办法
2666
查看次数

docker context create ecs myecs - 只需要一个参数

我正在尝试创建一个将自动与 AWS 的 ECS 集成的 Docker 上下文。 我正在关注本教程

作者只是这样做: docker context create ecs myecs并得到一个“选择一个集成”提示,而我得到一个错误,说它正好需要 1 个参数。

docker context create" requires exactly 1 argument.
See 'docker context create --help'.

Usage:  docker context create [OPTIONS] CONTEXT

Create a context
Run Code Online (Sandbox Code Playgroud)

amazon-web-services amazon-ecs docker

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

Vue2-传单地图在BoostrapVue模态中无法正确显示

这是我的问题-Vue2传单贴图在BootstrapVue模态中无法正确呈现。

这是视觉上的外观(应该只显示海洋)

在此处输入图片说明

<template>
  <div>
    <b-modal size="lg" :visible="visible" @hidden="$emit('clear')" title="Event details">
      <div class="foobar1">
        <l-map :center="center" :zoom="13" ref="mymap">
          <l-tile-layer :url="url" :attribution="attribution"></l-tile-layer>
          <l-marker :lat-lng="center"></l-marker>
        </l-map>
      </div>

      <template slot="modal-footer">
        <b-btn variant="danger" @click="deleteEventLocal(event.id)">Delete</b-btn>
      </template>
    </b-modal>
  </div>
</template>

<script>
import * as moment from "moment";
import { LMap, LMarker, LTileLayer } from "vue2-leaflet";
import { deleteEvent } from "./api";
import "vue-weather-widget/dist/css/vue-weather-widget.css";
import VueWeatherWidget from "vue-weather-widget";

export default {
  data() {
    return {
      center: L.latLng(event.latitude, event.longitude),
      url: "http://{s}.tile.osm.org/{z}/{x}/{y}.png",
      attribution:
        '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    };
  },
  props: { …
Run Code Online (Sandbox Code Playgroud)

javascript css leaflet vue.js bootstrap-4

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

如何将“| null”添加到接口的每个字段?

我有一个这样的界面:

interface TrainingSession {
  date: string;
  topic: string;
}
Run Code Online (Sandbox Code Playgroud)

我想创建一个表单,它将向我的 API 发送一个 /createTrainingSession 请求。在这种形式中,我想使用上面的界面来键入保存用户输入的数据结构。喜欢:

const initialFormInput : TrainingSession = {
  date: null,
  topic: null
}
Run Code Online (Sandbox Code Playgroud)

问题是,由于初始接口在两个字段中都需要一个字符串,因此我无法传递到null那里。想到的一种解决方案是null像这样扩展接口:

interface FormTrainingSession extends TrainingSession {
  date: string | null;
  topic: string | null;
}
Run Code Online (Sandbox Code Playgroud)

但这有点烦人 - 从头开始​​重写界面只是为了添加 null?

我喜欢如何Partial<TrainingSession>工作,但显然 Partial 添加| undefined到每个领域,而不是我想要的 - | null。是否有一个等价的 Partial,只是增加了 | 空值?

typescript

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

Javascript记忆

有人可以使用Javascript提供一个简单的记忆功能.我在网上搜索时发现了一些文章,但我没有看到很多.我找到的最好的文章是这个:

http://alivedise.github.io/blog/2012/12/22/javascript-memorization/

我理解缓存是什么,但这个例子对我来说太复杂了.我希望这里的任何人都可以提供一个简单的功能和电话,这样我就可以接受并开始更深入地理解这一点.

谢谢

javascript memoization

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