我的upload.js文件包含以下代码:
module.exports = {
up: function () {
const storage = require('@google-cloud/storage');
const fs = require('fs');
const gcs = storage({
projectId: 'MY_PROJECT_ID',
keyFilename: './service-account.json'
});
var bucket = gcs.bucket('MY_BUCKET');
bucket.upload('picture.jpg', function(err, file) {
if (err) throw new Error(err);
});
},
}
Run Code Online (Sandbox Code Playgroud)
它可以通过终端运行,但是如何在单击表单提交按钮或仅从其他文件中调用它?
当我尝试它给我:
无法读取未定义的属性“原型”
我对NodeJ很陌生,我真的不知道该怎么办。
不幸的是,Google文档对我没有任何帮助:/
鉴于下面的迷你Vuejs应用程序.
当我单击其中一个增量/减量按钮时,"计数器"组件中的值会更新,但"字母"中的值不会更新.
关于如何在这两个组件之间共享相同数据以便它们自动更新的任何想法?
var counter = Vue.extend({
props: ['start'],
template: '#counter',
data: function() {
return {
value: this.start
}
},
methods: {
increment: function() {
this.value++
},
decrement: function() {
this.value--
}
}
});
var alphabet = Vue.extend({
props: ['value'],
template: '#alphabet',
data: function() {
return {
value: 0
}
}
});
new Vue({
el: '#app',
data: {
val: 5
},
components: {
counter: counter,
alphabet: alphabet
}
});Run Code Online (Sandbox Code Playgroud)
<script id="counter" type="text/template">
<button @click="increment">+</button> {{ value }}
<button @click="decrement">-</button>
</script> …Run Code Online (Sandbox Code Playgroud)我是Xamarin Forms的新手.使用xamarin应用程序断点在Android下运行良好,但在UWP中失败.
检查选项project → Properties → Build → "Compile using the native code tool chain"导致导航无效.
NB:vs 2017是最新的(版本15.5.7)
使用 angular 4,我将带有空路径的路由重定向到导航栏组件。所以我添加了pathMatch: full这个条目并将其放在路由数组的顶部。
但我仍然收到以下错误:
zone.js:522 未处理的承诺拒绝:
路由配置无效:无法指定数组;
区域:根;
任务: Promise.then ;
值:ZoneAwareError {
__zone_symbol__error: Error: Invalid configuration of route '': Array cannot be specified
at Zone.run ( http://localhost:4200/polyfills.bundle.js:6405:43 ) [ => angular]
路由.component.ts
import {Route} from '@angular/router';
import { AppComponent } from './app.component';
import {NavbarComponent} from './navbar/navbar.component';
import {RegistrationComponent} from './registration/registration.component';
export const appRoutes:Route =[
{
path: '',
redirectTo: 'navbar',
pathMatch: 'full'
}, {
path: 'home',
component: NavbarComponent
}, {
path: 'navbar',
component: NavbarComponent …Run Code Online (Sandbox Code Playgroud) 我使用lazysizes库来延迟加载图像。跨度包含实际图像 src,并且img在页面源中保留标签以实现更好的 SEO。
该img工作清楚,src="/resources/FolderIMAGES/795_t.JPG"正确添加时对用户可见,但加入了放到背景图片的事件监听器span元素触发所有图片加载,即使这些都不是对用户可见...
lazysizes 存储库问题中心的一些人在评论中说,lazybeforeunveil即使图像不可见,它也会触发事件的正常行为。
所以我的问题是,检测图像何时可见的正确事件是什么,我应该如何传递data-bg属性值来填充backgroundImage样式属性?鉴于文档说lazybeforeunveil应该用于处理背景图像延迟加载。
我不知道它是否会影响任何东西,但 img 已经display: none更改为,height: 0px !important;width: 0px !important;以便lazysizes 可以检测到图像。
document.addEventListener('lazybeforeunveil', function(e){
var bg = e.target.getAttribute('data-bg');
if(bg){
e.target.style.backgroundImage = 'url(' + bg + ')';
} });
<img itemprop="image" class=" lazyloaded" data-src="/resources/FolderIMAGES/795_t.JPG" title="Anel Magnético G2 - Wizard Pk Ring" alt="Anel Magnético G2 - Wizard Pk Ring" >
<span class="image lazyloaded" data-bg="/resources/FolderIMAGES/795_t.JPG " alt="Anel …Run Code Online (Sandbox Code Playgroud) 我写了一个宏:
macro_rules! test {
($trait:tt<$($param:literal)+>) => {
{
println!("{}", stringify!($($param)++));
}
};
}
Run Code Online (Sandbox Code Playgroud)
对于$param重复分隔符,我无法使用+重复“op”的字符。
输出看起来像1 2 3 +,但我怎样才能让它变成1 + 2 + 3这样呢?
您好,我有一个连接数组,如下所示:
var connections =[
{
"source": "l1",
"target": "l2"
},
{
"source": "l2",
"target": "l4"
},
{
"source": "l2",
"target": "l3"
},
{
"source": "l4",
"target": "l5"
},
]
Run Code Online (Sandbox Code Playgroud)
它继续源和目标。现在想要使用某些函数找到两个节点之间的路径。假设函数findConnections("l2", "l5")将返回如下所示的数组
var answer =[
{
"source": "l2",
"target": "l4"
},
{
"source": "l4",
"target": "l5"
},
]
Run Code Online (Sandbox Code Playgroud)
我不知道如何才能实现这一目标?我尝试了简单的 JavaScript 但失败了。我认为使用underscore.js或lodash.js我们可以实现这一点?如果有人提供解决方案或给出提示,这真的会有帮助吗?
我在mongoDB中使用聚合方法进行分组,但是当我使用$group它时,它返回了我用来分组的唯一字段。我已经尝试过了,$project但是也不起作用。我也试过了$first ,但效果很好,但是结果数据现在采用了不同的格式。
我需要的响应格式如下:
{
"_id" : ObjectId("5b814b2852d47e00514d6a09"),
"tags" : [],
"name" : "name here",
"rating" : "123456789"
}
Run Code Online (Sandbox Code Playgroud)
在我的query.response中添加$ group之后,_id的值将更改。(并且$ group仅接受_id,如果我尝试其他任何关键字,则会引发累加器错误。请也对此进行解释。)
{
"_id" :"name here" //the value of _id changed to the name field which i used in $group condition
}
Run Code Online (Sandbox Code Playgroud)
我必须删除名称字段中的重复项,而无需更改任何结构和字段。我也将nodeJS与猫鼬一起使用,因此请提供与其兼容的解决方案。
我在本教程后使用了google place API,但我收到以下错误:
找不到具有未指定名称属性的控件
我也试过这个所有提示stackoverflow链接
码
<div class="form-group">
<input #search
type="text"
placeholder="search for location"
autocorrect="off"
autocapitalize="off"
spellcheck="off"
class="form-control"
[formControl]="searchControl"
name="searchControl">
</div>
Run Code Online (Sandbox Code Playgroud) 当我尝试添加@angular/material到我的项目时,出现此错误。
使用 Angular Cli:7.2.1,节点 11.6.0
找不到模块 '@angular-devkit/schematics/tasks'
错误:
在 Function.Module._resolveFilename (internal/modules /cjs/loader.js:603:15)
处找不到模块 '@angular-devkit/schematics/tasks' Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers. js:22:18)
在对象。(/Users/ricardobaeza/Projects/node_modules/@angular/material/schematics/ng-add/index.js:10:17)
在 Module._compile (internal/modules/cjs/loader.js:721:30)
在 Object .Module._extensions..js (internal/modules/cjs/loader.js:732:10)
在 Module.load (internal/modules/cjs/loader.js:620:32)
在 tryModuleLoad (internal/modules/cjs/loader.js:560:12)
在 Function.Module._load (internal/modules/cjs/loader.js:552:3)
我有一个应用了以下 CSS 背景规则的按钮:
background-image:url('/images/button_1_normal.png');
Run Code Online (Sandbox Code Playgroud)
我想用 JavaScript 更改按钮的背景。我尝试了以下方法,但没有成功。
document.getElementById(step2).style.backgroundImage = "url('images/button_1_active.png') no-repeat";
Run Code Online (Sandbox Code Playgroud)
问题是什么?谢谢
我知道C++应该比Python 3快得多,因为它是一种编译语言而不是解释语言.
我编写了两个程序,使用蒙特卡罗模拟来计算Pi,一个在Python 3中,另一个在C++中.
Python的结果比C++快大约16倍.如下图所示,重复值为(10,000,000),Python需要8.5秒,而C++需要137.4秒.
我是C++的新手,但我找不到解释这种行为的在线帖子.
根据这篇文章, C++一般应该比Python快10倍 - 100倍,这显然不是我的情况.
请帮助我理解为什么Python在我的情况下比C++快得多.
我的结果:
Python源代码:
from random import random
import time
import sys
class MonteCarloSimulator(object):
def __init__(self, value):
self.value = value
if sys.platform == "win32":
self.G = ''
self.R = ''
self.END = ''
else:
self.G = '\033[92m'
self.R = '\033[1;31m'
self.END = '\033[0m'
def unit_circle(self, x, y):
if (x ** 2 + y ** 2) <= 1:
return True
else: …Run Code Online (Sandbox Code Playgroud) 如何让我的机器人离开公会?我试过这个:
case `leave`:
if(message.author.id !=='196701848239865866')
return message.channel.send(`**»** ${message.author}, you don't have permission to do that!`);
var guildID = bot.guild.find()
guildID.leave()
break;
Run Code Online (Sandbox Code Playgroud) javascript ×7
angular ×3
node.js ×2
performance ×2
angular-cli ×1
background ×1
breakpoints ×1
c# ×1
c++ ×1
components ×1
css ×1
discord ×1
discord.js ×1
graph ×1
html ×1
lazy-loading ×1
lodash ×1
macros ×1
model ×1
mongodb ×1
mongoose ×1
montecarlo ×1
python ×1
rust ×1
simulation ×1
uwp ×1
vue.js ×1
xamarin ×1