我有一个 Vue 3 应用程序。这个应用程序依赖于Vite、Vue Router、Pinia。具体版本有:
该应用程序有一个代表“页面”的文件组件。这个单个文件组件的定义如下:
页面.vue
<template>
<div>
Hello! Thank you for visiting {{ id }}!
</div>
</template>
<script setup>
import { onMounted } from 'vue';
import { useStore } from '../stores/store';
const myStore = useStore();
onMounted(() => {
const props = defineProps({ id:Number });
console.log(props);
});
</script>
Run Code Online (Sandbox Code Playgroud)
我的目标是当有人访问 时https://[my-site].com/pages/{some-id},我会id通过 URL 获取传入的信息。目前,我的路线定义如下:
{
path: '/pages/:id',
name: 'page',
component: () => import('../views/page.vue'),
props: true
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,由于id是我的路线上的参数,因此我可以使用该[defineProps][1]方法。当加载单个文件组件时,我没有看到id. …
我正在尝试在测试中获取元素的属性。我的测试如下所示:
test(`Should be at least 5 characters long`, async({ page }) => {
await page.goto('http://localhost:8080');
const field = await page.locator('id=emailAddress');
const _attribute = await field.getAttribute('minlength');
const minlength = Number(_attribute);
await expect(minlength).toBeGreaterThanOrEqual(5);
});
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我可以看到该minlength值为0。这是因为_attribute是null。但是,我不明白为什么。field是一个Locator. 但是,我似乎无法获取该属性或其值。我究竟做错了什么?
我有一个依赖于Vite 的Vue.js 应用程序。在此应用程序中,我需要将两个静态文件复制到我的dist目录中:favicon.ico和manifest.json. 我的vite.config.js文件如下所示:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig(({command, mode }) => {
return {
assetsDir: 'res',
plugins: [vue()],
publicDir: 'dist',
root: 'src',
build: {
emptyOutDir: true,
outDir: '../dist'
}
}
});
Run Code Online (Sandbox Code Playgroud)
我的目录结构如下所示:
/
/dist
/src
/assets
favicon.ico
manifest.json
/res
/css
theme.css
App.vue
main.js
index.html
package.json
README.md
vite.config.js
Run Code Online (Sandbox Code Playgroud)
当我使用 编译程序时,我可以看到在目录中创建的npm run build名为 的文件。但是,我未能成功地将和文件复制到我需要的目录中。我尝试添加到选项中。然而,这没有用。我还尝试在该目录下创建一个目录,以便遵循本文档。但是,这并没有将文件移动到目录中。我究竟做错了什么?index.htmldistfavicon.ico …
我有一些 ASP.NET 中间件,可以分析传入的请求。根据其中可用的内容HttpRequest,我想添加一个可以在代码中使用的自定义属性。我的问题是,有没有办法添加属性HttpRequest以便我可以在控制器中访问它?例如,在我的 中Controller,我想做这样的事情:
namespace MyWebsite.Controllers
{
public class MyController : Controller
public IActionResult Index()
{
if (this.Request.MyProperty == null)
{
return View("~/Views/NoExist.cshtml");
}
return View ("/Views/Index.cshtml");
}
}
Run Code Online (Sandbox Code Playgroud)
MyProperty表示我想通过自定义中间件注入或添加的自定义属性。这可能吗?如果是这样,怎么办?如果不是,推荐的方法是什么?
谢谢你!
我有一个电子应用程序。我需要从本地计算机获取环境变量的值以在渲染器线程上使用。我想在应用程序启动时将此值传递给渲染器线程。我知道在main.js文件中,我可以像这样获取环境变量:
main.js
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600
});
win.loadFile('index.html');
// Retrieve the environment variable value
const variableValue = process.env.MY_ENVIRONMENT_VARIABLE;
console.log(`Variable value: ${variableValue}`);
// Send the variable and it's value to the renderer.
win.webContents.send('initialize', { 'variableName':variableValue });
}
Run Code Online (Sandbox Code Playgroud)
上面成功地将环境变量的值打印到终端窗口。但是,我需要在浏览器端使用这个值。我如何在那里获取变量的值?
谢谢你!
我正在使用 Vue.js 3.0 编写一个 Vue.js 应用程序。我用它来学习组合 API。我不清楚的一件事是当存储值更新时如何有条件地更新我的组件 UI。为了演示我的问题,我创建了这个 fiddle。代码详细在这里:
JavaScript
const store = {
state: reactive({
result = null
}),
generateNewValue() {
this.state.result = Math.floor(Math.random() * 10);
}
};
const MyApp = {
setup() {
return {
}
}
}
const myApp = Vue.createApp(MyApp)
myApp.component("banner",
{
template: '<button @click="onGenerateClick">generate</button>',
setup(props) {
console.log('setting up...');
},
methods: {
onGenerateClick() {
store.generateNewValue();
}
}
}
);
myApp.component("content", {
template: '<div><span>Content</span><button @click="onGenerateClick">generate</button></div>',
methods: {
onGenerateClick() {
store.generateNewValue();
}
}
});
myApp.mount('#my-vue')
Run Code Online (Sandbox Code Playgroud)
超文本标记语言 …
我有一个用 JavaScript 编写的单页应用程序。我当前正在使用JavaScript API将事件记录到 Azure Application Insights 。此时,我正在使用如下代码记录事件:
let eventLog = {
name: 'Custom Event Name',
customDimensions: {
target: 'app'
},
customMeasurements: {
totalTime: '00:00:01.1234'
}
};
appInsights.trackEvent(eventLog);
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,我注意到自定义事件正在写入我的 Application Insights 实例。虽然 Application Insights 中显示了正确的事件名称,但我没有看到任何自定义维度或自定义度量。
如何通过 JavaScript API 将自定义维度和自定义测量以及自定义事件记录到 Azure Application Insights?
谢谢你!
我有一个使用 Bootstrap 5(Beta 1)的网页。在此页面上,我需要在该区域的右下角添加一个按钮main。为了实现这一目标,我尝试使用Bootstrap 5 中的定位实用程序。我当前的代码如下所示:
<body class="d-flex flex-column h-100">
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" href="/">Pictures</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
</header>
<main role="main" class="flex-fill" style="background-color:pink;">
<div>
<div class="container">Here</div>
<div class="position-relative">
<div class="position-absolute bottom-0 end-0">
<button class="btn btn-primary">Add Picture</button>
</div>
</div>
</div>
</main>
<footer class="footer mt-auto bg-light">
<div class="container">
Hello
</div>
</footer>
</body>
Run Code Online (Sandbox Code Playgroud)
不幸的是,我似乎无法将“添加图片”按钮放置在元素右下角、main页脚上方。我尝试了定位实用程序的几种组合。但是,我似乎无法让它正常工作。我究竟做错了什么?
我有一个 C# 控制台应用程序,其中包含许多异步任务。其中一项任务是抛出异常。但是,我了解到主机代码没有按预期处理该场景。为了了解发生了什么,我决定进行一个测试。此测试的目的是创建一个Task异步运行的程序,但故意抛出异常。我想看看返回的内容是否符合主机代码的预期。
令我惊讶的是,该Task对象的IsCompletedSuccessfully属性是true,IsFaulted属性是false。然而,我期待IsCompletedSuccessfully成为false并且IsFaulted成为true。代码如下所示:
[Fact]
public void Repro()
{
var task = new Task(async () => {
var operand1 = 2;
var operand2 = 0;
var result = operand1 / operand2;
Thread.Sleep(250);
await Task.CompletedTask;
});
task.RunSynchronously();
Console.WriteLine($"Cancelled: {task.IsCanceled}, Completed: {task.IsCompleted}, Completed Successfully: {task.IsCompletedSuccessfully}, Faulted: {task.IsFaulted}");
if (task.Exception != null)
{
Console.WriteLine("There was an exception");
}
Assert.Equal(false, task.IsCompletedSuccessfully);
Assert.Equal(true, task.IsFaulted);
} …Run Code Online (Sandbox Code Playgroud) 我有一个 C# 控制台应用程序。在这个应用程序中,我有一个方法可以调用DoWorkAsync。对于此问题的上下文,此方法如下所示:
private async Task<string> DoWorkAsync()
{
System.Threading.Thread.Sleep(5000);
var random = new Random();
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var length = random.Next(10, 101);
await Task.CompletedTask;
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
Run Code Online (Sandbox Code Playgroud)
我DoWorkAsync从另一种方法调用,该方法确定 a) 这将运行多少次,以及 b) 每个调用是并行还是按顺序运行。该方法如下所示:
private async Task<Task<string>[]> DoWork(int iterations, bool runInParallel)
{
var tasks = new List<Task<string>>();
for (var i=0; i<iterations; i++)
{
if (runInParallel)
{
var task = Task.Run(() => DoWorkAsync());
tasks.Add(task);
}
else
{
await DoWorkAsync();
}
}
return tasks.ToArray(); …Run Code Online (Sandbox Code Playgroud) javascript ×5
c# ×3
vue.js ×3
asp.net-core ×1
asynchronous ×1
azure ×1
bootstrap-5 ×1
css ×1
electron ×1
middleware ×1
playwright ×1
vite ×1
vuejs3 ×1