小编Kok*_*oko的帖子

未找到Babel命令

我按照Babel '入门'页面的说明安装了babel-cli工具.

从我的项目文件夹中的终端:

npm install --save-dev babel-cli
Run Code Online (Sandbox Code Playgroud)

在此之后,有一个带有babel-cli文件夹的node_modules目录,但是没有创建package.json.npm还显示以下错误:

npm WARN enoent ENOENT: no such file or directory, open '/Users/MyName/Sites/Tutorials/Babel2/package.json
Run Code Online (Sandbox Code Playgroud)

当试图运行babel时,我明白了:

babel src -d lib
-bash: babel: command not found
Run Code Online (Sandbox Code Playgroud)

我安装了最新版本的nodejs/npm.我运行了npm update -g,我编辑了我的.bash_profile文件,包括:

export PATH=$PATH:/Users/MyName/npm/bin
export PATH=/usr/local/share/npm/bin:$PATH
Run Code Online (Sandbox Code Playgroud)

我没有使用浏览器等其他npm工具.为什么巴贝尔不被认可?

npm babeljs

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

如何在Microsoft的新Visual Studio代码中编译c#?

我安装了Microsoft新代码编辑器"Visual Studio Code " 的预览版.这似乎是一个很好的工具!介绍中提到你可以使用它编写c#,但是安装文档没有提到如何实际编译c#文件.您可以将"mono"定义为" launch.json "文件中的类型,但这还没有做任何事情.按F5会导致:"确保从启动下拉列表中选择一个配置"...此外,intellisense不适用于c#?如何设置任何包含框架的路径?

Launch.json:

"configurations": [
        {
            // Name of configuration; appears in the launch configuration drop down menu.
            "name": "Cars.exe",
            // Type of configuration. Possible values: "node", "mono".
            "type": "mono",
            // Workspace relative or absolute path to the program.
            "program": "cars.exe",
        }, 
        {
            "type": "mono",
        }
Run Code Online (Sandbox Code Playgroud)

c# visual-studio-code

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

如何在没有SDK或自定义应用ID的情况下创建Facebook共享按钮?

我正在查看Facebook的分享按钮最新更新. 似乎不再可能在网站中包含分享按钮而不包括Facebook javascript SDK,或者在某个地方提供Facebook应用程序以提供应用程序ID?

分享按钮示例1使用Facebook SDK

FB.ui({
  method: 'share',
  href: 'https://developers.facebook.com/docs/',
}, function(response){});
Run Code Online (Sandbox Code Playgroud)

共享按钮示例2使用自定义应用程序ID

https://www.facebook.com/dialog/share?
  app_id=145634995501895
  &display=popup
  &href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2F
  &redirect_uri=https%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fexplorer
Run Code Online (Sandbox Code Playgroud)

问题:如何使用一行代码为Facebook构建简单明了的共享按钮,不需要库和应用程序ID?

facebook

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

如何在打字稿中使用fetch

我在Typescript中使用window.fetch,但我无法将响应直接转换为我的自定义类型:

我通过将Promise结果转换为中间的'any'变量来解决这个问题.

这样做的正确方法是什么?

import { Actor } from './models/actor';

fetch(`http://swapi.co/api/people/1/`)
      .then(res => res.json())
      .then(res => {
          // this is not allowed
          // let a:Actor = <Actor>res;

          // I use an intermediate variable a to get around this...
          let a:any = res; 
          let b:Actor = <Actor>a;
      })
Run Code Online (Sandbox Code Playgroud)

promise typescript

33
推荐指数
3
解决办法
5万
查看次数

Git合并是不可能的,因为我有未合并的文件

GIT继续以无用的错误警告让我感到困惑:(这个确实应该获奖:

"git merge是不可能的,因为你有未合并的文件"

我的情况:我在github上的主分支编辑(直接在浏览器中),同时我的本地主分支也被编辑.

愚蠢的是,我认为你可以简单地合并两个版本并完成它,但唉,我无法合并 - 因为我的文件是未合并的.

git merge remote/master
Run Code Online (Sandbox Code Playgroud)

结果是

error: merge is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
Run Code Online (Sandbox Code Playgroud)

因此,在添加并提交本地更改然后再次尝试合并之后,我得到:

merge: remote/master - not something we can merge
Run Code Online (Sandbox Code Playgroud)

很明显,我在这里缺少必要的东西......我对合并意味着什么有错误的想法?如何修复具有不同远程主/本地主分支的问题?

git merge github

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

React复选框事件和处理程序的Typescript类型?

我在Typescript中构建类似React示例的东西.目标是让父母拥有一个州,并创建几个无状态子组件,将他们的点击次数传递回父级.

由于示例是在Javascript中,我不知道输入框事件的类型和onChange处理程序是什么......?我尝试了几种选择React.MouseEvent<HTMLInputElement>,但这只是猜测......

父组件 创建imageRows并传递处理程序:

render() {
  <div>
    <ImageRow key={el.url} onChange={this.onChange}/>
  </div>
 }
 // what should the type of e be?
 onChange(e:any){
 }
Run Code Online (Sandbox Code Playgroud)

和ImageRow组件

export interface ImageRowProps { 
  genre: Array<number>
  url: string
  onChange : any // what is the type of the callback function?
}

export class ImageRow extends React.Component<ImageRowProps> {
  render() {
    return <div className="imagerow">
        <input type="checkbox" key={index} onChange={this.props.onChange} defaultChecked={(num == 1)}/>
    </div>
}
Run Code Online (Sandbox Code Playgroud)

编辑

类似的问题只显示事件类型,而不是处理程序类型.当我更改事件类型时:

onChange(e: React.FormEvent<HTMLInputElement>){
    console.log(e.target.value)
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Property 'value' does not exist …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs

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

如何仅使用tasks.json在Visual Studio代码中链接任务?

我一直在浏览Visual Studio Code的文档,以弄清楚如何将多个连续任务添加到tasks.json文件中.

tasks数组仅允许为同一命令创建不同的参数.在这个例子中命令是echo.

{
    "version": "0.1.0",
    "command": "echo",
    "isShellCommand": true,
    "args": [],
    "showOutput": "always",
    "echoCommand": true,
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "hello",
            "args": ["Hello World"]
        },
        {
            "taskName": "bye",
            "args": ["Good Bye"]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

tasks.json是否允许连续执行多个任务?例如,tsc接下来是uglify

visual-studio-code vscode-tasks

17
推荐指数
2
解决办法
5190
查看次数

如何在不使用vue-cli的情况下使用vue-loader

我试图将使用webpack转换.vue文件的Vue项目的绝对最低限的例子放在一起.

我的目标是详细了解每个构建步骤.大多数教程建议使用vue-cli和使用webpack-simple配置.尽管这种设置有效,但对我的简单目的而言似乎有些过分.现在我不想要使用热模块重新加载的babel,linting或实时Web服务器.

一个最小的例子,只是import Vue from 'vue'工作!Webpack将vue库和我自己的代码编译成一个包.

但现在,我想将vue-loader添加到webpack配置中,以便将.vue文件转换成文件.我已经安装了vue loader:

npm install vue-loader
npm install css-loader
npm install vue-template-compiler 
Run Code Online (Sandbox Code Playgroud)

我已经在webpack配置中添加了vue-loader:

var path = require('path')

module.exports = {
  entry: './dev/app.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  }
};
Run Code Online (Sandbox Code Playgroud)

我创建了hello.vue

<template>
  <p>{{greeting}} World</p>
</template>

<script>
export default …
Run Code Online (Sandbox Code Playgroud)

webpack vue.js

17
推荐指数
1
解决办法
7030
查看次数

如何检查Vue是否处于开发模式?

当我运行我的Vue应用程序时,控制台显示:

You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html
Run Code Online (Sandbox Code Playgroud)

所以现在我想通过使用以下方法检查Vue是否在我的模板中进行开发:

console.log("mode is " + process.env.NODE_ENV)
Run Code Online (Sandbox Code Playgroud)

但是那只记录undefined 是否有不同的方法在Vue中找到NODE_ENV?

我的webpack配置有这个部分:

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}
Run Code Online (Sandbox Code Playgroud)

也许相关:我使用的是typescript,所以我包含了这种类型的声明:

declare var process: {
    env: …
Run Code Online (Sandbox Code Playgroud)

typescript webpack vue.js

17
推荐指数
6
解决办法
9286
查看次数

为什么使用委托和协议而不是仅仅在Swift中传递实例?

我试图在Swift中的视图之间传递变量,并遇到了相当抽象的协议和委托概念.

然后我尝试在第二个视图中存储对第一个视图的引用,并直接调用函数.这似乎有效:

屏幕1

class Screen1: UIViewController {

    var myName = "Screen1"

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    //
    // checking if the segue to screen 2 is called and then passing a reference
    //
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        if segue.identifier == "screen2Segue"{
            let vc = segue.destinationViewController as Screen2
            vc.storedReference = self
        }
    }

    func getName() -> String {
        return myName
    }
}
Run Code Online (Sandbox Code Playgroud)

屏幕2

class Screen2: UIViewController {

    var storedReference:Screen1!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    func testReference() …
Run Code Online (Sandbox Code Playgroud)

delegates protocols swift

15
推荐指数
3
解决办法
4950
查看次数