我正在尝试使用 JavaScript 将多个 Graphql 查询合并为一个查询。
我正在寻找这样的东西:
let query3 = mergeQueries(query1, query2);
Run Code Online (Sandbox Code Playgroud)
我们事先不知道将合并哪些查询。
假设我有这样的查询:
输入查询1:
{
post(id: 1234) {
title
description
}
}
Run Code Online (Sandbox Code Playgroud)
输入查询2:
{
post(id: 1234) {
tags
author {
name
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我希望结果 query3 为:
result query3:
{
post(id: 1234) {
title
tags
description
author {
name
}
}
}
Run Code Online (Sandbox Code Playgroud)
这与 lodash_.merge()为 JSON 对象所做的功能相同,但随后使用 Graphql 查询而不是 JSON 对象。
我正在为网站使用 Vuetify 和 Vuetify/Datatables。现在我想要computed表格的每一行都有一些属性。
为此,我可能需要制作<template>元素的一个组件并向该组件添加计算属性。我试过了,<template is="myComponent" :m="props.item">但这没有用。
<v-data-table
:headers="headers"
:items="items"
hide-actions
class="elevation-1"
>
<template slot="items" slot-scope="props">
<td>{{ THIS_VALUE_COMPUTED }}</td>
<td class="text-xs-right">{{ props.item.calories }}</td>
<td class="text-xs-right">{{ props.item.fat }}</td>
<td class="text-xs-right">{{ props.item.carbs }}</td>
<td class="text-xs-right">{{ props.item.protein }}</td>
<td class="text-xs-right">{{ props.item.iron }}</td>
</template>
</v-data-table>
Run Code Online (Sandbox Code Playgroud) (此问题已针对 JavaScript 回答,见下文,但此问题特定于 TypeScript,其行为不同)
我正在尝试使用打字稿在 Vue3.0 中使用异步功能。
没有异步,这段代码很好用:
// file: components/HelloWorld.vue
<template>
<div class="hello">
<h1>{{ msg }}</h1>
</div>
</template>
<script lang="ts">
import {defineComponent} from 'vue'
export default defineComponent({
name: 'HelloWorld',
props: {
msg: String,
},
async setup() { // <-- this works without 'async'
const test = 'test'
// await doSomethingAsynchronous()
return {
test,
}
},
})
</script>
Run Code Online (Sandbox Code Playgroud)
随着async setup()组件“HelloWorld”从页面中消失,Firefox 控制台告诉我
"Uncaught (in promise) TypeError: node is null (runtime-dom.esm-bundler.js)"
Run Code Online (Sandbox Code Playgroud)
当我更改async setup()为 时setup(),代码有效,但随后我将无法在 …
我试图将一个组件包含到另一个组件中,但在浏览器控制台中收到错误“无法解析组件:应用程序概述表”。
父组件“src/pages/ApplicationsOverview.vue”:
<template>
<q-page class="flex flex-center">
<applications-overview-table></applications-overview-table>
</q-page>
</template>
<script>
import ApplicationsOverviewTable from '../components/application/OverviewTable.vue';
export default {
name: 'ApplicationsOverviewPage',
components: [ApplicationsOverviewTable],
setup() {
console.log('loading applications overview');
return {};
},
};
</script>
<style></style>
Run Code Online (Sandbox Code Playgroud)
子组件“src/applications/OverviewTable.vue”:
<template>
<div class="q-pa-md">
<q-table title="Aanvragen" :rows="rows" :columns="columns" row-key="name" />
</div>
</template>
<script>
const columns = [ ... ];
const rows = [ ... ];
export default {
name: 'ApplicationsOverviewTable',
setup() {
return {
columns,
rows,
};
},
};
</script>
Run Code Online (Sandbox Code Playgroud)
我可以看到正在加载父组件,因为控制台中显示了控制台消息“正在加载应用程序概述”。
我还可以看到路径OverviewTable.vue是正确的,因为如果我更改路径,则会出现另一个错误。
我尝试更改<applications-overview-table>为,<ApplicationsOverviewTable> …
我尝试从Dart中的地图列表中获取id. 在JavaScript中它将是这样的:
var list = [{id:3, name:'third'}, {id:4, name:'fourth'}];
var result = list.map(function(x){return x.id;});
Run Code Online (Sandbox Code Playgroud)
这应该给出结果
[3, 4]
Run Code Online (Sandbox Code Playgroud)
在Dart有一个简单的方法吗?
到目前为止,我能够做到这一点(在Dart中):
var list = [{'id':3, 'name':'third'},{'id':4, 'name':'fourth'}];
var result = list.map((x) => x['id']);
Run Code Online (Sandbox Code Playgroud)
结果是"MappedListIterable"(不确定是什么),你不能result[0]像普通List那样使用.我怎样才能列出这个?
我正在使用Rust Rocket框架生成一个简单的网页.
当去索引页面"/"时:
#[get("/")]
fn page_index() -> &'static str {
r#"
<title>GCD Calculator</title>
<form action="/gcd" method="post">
<input type="text" name="n" />
<input type="text" name="n" />
<button type="submit">Compute GCD</button>
</form>
"#
}
Run Code Online (Sandbox Code Playgroud)
服务器控制台告诉我
GET / text/html:
=> Matched: GET /
=> Outcome: Success
=> Response succeeded.
Run Code Online (Sandbox Code Playgroud)
但是我的浏览器告诉我Content-Type是text/plain.
如何使Rocket正确响应text/html.我做错了什么还是Rocket?
编辑:我停止尝试让它工作。
我正在使用 Vue-cli ( https://github.com/chrisvfritz/vue-enterprise-boilerplate ),它在水下使用 Webpack 创建网站。
现在我想更改我的webpack.config.js但是这个文件不存在。
vue.config.js包含一个configureWebpack属性,但这似乎与普通 Webpack 配置的格式不同。
我想使用的 Webpack 配置是这样的:
// Webpack config
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const StartServerPlugin = require('start-server-webpack-plugin');
module.exports = {
entry: ['webpack/hot/poll?1000', './src/index'],
watch: true,
target: 'node',
node: {
__filename: true,
__dirname: true
},
externals: [nodeExternals({ whitelist: ['webpack/hot/poll?1000'] })],
module: {
rules: [
...
]
},
plugins: [
new StartServerPlugin('server.js'),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({ …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Laravel 中设置测试,但我想运行与通常运行的迁移不同的迁移。
我运行的用于启动数据库的迁移从生产环境导入数据。
为了进行测试,我想使用一个名为“test”的不同数据库,并且我想用测试数据而不是生产数据填充此测试数据库。
我添加了一个config/database.php使用“测试”数据库的“测试”连接:
'connections' => [
'mysql' => [
'database' => env('DB_DATABASE', 'forge'),
...
],
'testing' => [
'database' => 'test',
...
],
],
Run Code Online (Sandbox Code Playgroud)
我设置phpunit.xml使用这个“测试”连接:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit ...>
...
<php>
<env name="DB_CONNECTION" value="testing"/>
...
</php>
</phpunit>
Run Code Online (Sandbox Code Playgroud)
现在我想使用测试数据初始化这个“测试”数据库,使用来自与默认文件夹不同的文件夹的迁移。
我可以像这样使用正常的迁移:
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
abstract class TestCase extends BaseTestCase
{
use DatabaseMigrations;
public function setUp(): void
{
parent::setUp();
$this->seed();
}
}
Run Code Online (Sandbox Code Playgroud)
但这使用默认文件夹database/migrations。我想将测试迁移放在文件夹中tests/database/migrations。
有没有办法让use …
我试图(深入)观察 Vue 3 中响应式对象的任何变化:
\nimport { reactive, watchEffect } from \'vue\';\n\nconst settings = reactive({\n panes: {\n left: {\n defaultAction: "openInOtherPane",\n },\n right: {\n defaultAction: "openInThisPane",\n },\n },\n showMenu: false,\n isDrawerOpen: false,\n});\n\nwatchEffect(() => {\n console.log(\'The new settings are\', settings);\n});\n\n// Try to change a setting (this does not trigger watchEffect)\nsettings.panes.left.defaultAction = "none";\nRun Code Online (Sandbox Code Playgroud)\n这段代码有两个问题:
\nProxy { <target>: {\xe2\x80\xa6}, <handler>: {\xe2\x80\xa6} }我也尝试过watch:
watch(\n () => settings,\n settings => {\n …Run Code Online (Sandbox Code Playgroud) 我有一个具有泛型的函数,它是 1 个元素的元组或 2 个元素的元组。
我想确保函数中使用的所有属性都使用相同长度的元组。
type TypeA = [string] // Tuple of 1 element
type TypeB = [string, string] // Tuple of 2 elements
type Header = TypeA | TypeB
interface SomeObject<H extends Header> {
prop1: H
prop2: H
}
function useHeader<H extends Header>(someObject:SomeObject<H>) {
// do something
}
useHeader({
prop1: ["tuple of 1 element"],
prop2: [
"tuple of",
"2 elements"
] // <-- I want an error here, because prop1 and prop2 use diffrent tuples
})
Run Code Online (Sandbox Code Playgroud)
我注意到,当我更改TypeA …
javascript ×4
vue.js ×3
vuejs3 ×3
typescript ×2
arrays ×1
async-await ×1
content-type ×1
dart ×1
graphql ×1
laravel ×1
php ×1
phpunit ×1
rust ×1
tuples ×1
type-safety ×1
vue-cli ×1
vue-sfc ×1
vuetify.js ×1
watch ×1
webpack ×1