在我的 ASP.NET Core 2.2 WebApi 项目中,我想将配置加载appsettings.json到强类型对象中。
appsettings.json 有以下配置部分:
{
"MySettings1": {
"Name": "John Smith",
"Age": "25",
}
}
Run Code Online (Sandbox Code Playgroud)
我想加载到强类型对象中MySettings:
public class MySettings
{
public string Name { get; set; }
public int Age { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我可以在我的Startup.ConfigureServices()方法中这样做:
services.Configure<MySettings>(configuration.GetSection("MySettings1"));
Run Code Online (Sandbox Code Playgroud)
或者像这样:
services.AddOptions<MySettings>().Bind(configuration.GetSection("MySettings1"));
Run Code Online (Sandbox Code Playgroud)
这两种方法有什么区别?它们都工作正常,因为我能够在这两种情况下获得适当的IOptions<MySettings>注入实例HomeController。
在某些特定情况下,我应该使用一种方法而不是另一种方法吗?(例如,将来我可能希望在从配置填充 MySettings 对象后添加某种运行时验证,所以在这种情况下,我应该更喜欢一种方法吗?)
我在 Vue 文档中找不到 的确切定义Dom template,但我在几个地方看到它被提到,例如这里: https: //v3.vuejs.org/style-guide/#self-ending-components-strongly-recommended
那么 DOM 模板到底是什么?这是 Vue 的概念还是更通用的概念(例如某些规范中定义的 HTML 概念)?它们只是<template>Vue 可以附加到外部标签的 HTML 元素,还是也可以是内部<template>标签?欢迎举例。
在阅读有关SameSite属性的内容时,我遇到了这个术语top-level navigation。
据我了解,这是当用户website1.com在浏览器中打开,然后单击将浏览器导航到其他网站的链接时,例如。website2.com。但这是一个宽松的定义。
top-level navigation那么浏览器术语到底是什么?是否有一些规范或 RFC 对这个术语有严格的定义?
除了点击指向另一个网站的链接(即在<a href="website2.com">website2.com</a>website1.com 上)之外,是否可以通过其他方式触发它?如果我website2.com直接在浏览器的导航栏中输入 url ,这会被视为 吗top-level navigation?
另外,除了与 cookie 和属性top-level navigation一起使用之外,在浏览器/http/安全的其他领域也很重要吗?SameSite
我有应用程序,用户可以在其中以不同的角色登录,例如。seller,buyer和admin。对于每个用户,我想在同一路径上显示仪表板页面,例如。http://localhost:8080/dashboard
但是,每个用户都会在不同的 vue 组件中定义不同的仪表板,例如。SellerDashboard,BuyerDashboard和AdminDashboard。
所以基本上,当用户打开http://localhost:8080/dashboardvue 应用程序时,应该根据用户角色(我存储在 vuex 中)加载不同的组件。同样,我想将它用于其他路线。例如,当用户进入个人资料页面时,http://localhost:8080/profile应用程序应根据登录用户显示不同的个人资料组件。
所以我希望所有用户角色都有相同的路线,而不是每个用户角色都有不同的路线,例如。我不希望用户角色将被包含在URL类似以下内容:http://localhost:8080/admin/profile和http://localhost:8080/seller/profile等...
如何使用 vue 路由器实现此场景?
我尝试使用子路由和每条路由保护的组合beforeEnter来解析基于用户角色的路由。这是一个代码示例:
在router.js 中:
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '@/store'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'home',
component: Home,
beforeEnter: (to, from, next) => {
next({ name: store.state.userRole })
},
children: …Run Code Online (Sandbox Code Playgroud) Vuetify 2.0.0-beta.0刚刚发布,我想尝试一下并在新的vue测试应用程序中试用。但是,当我尝试将其安装在新的新项目中时出现错误。这是我已采取的步骤。
我使用@vue/cli v3.8.2默认设置创建一个新项目:
vue create testapp
Run Code Online (Sandbox Code Playgroud)
这给了我成功的结果:
Successfully created project testapp.
Get started with the following commands:
$ cd testapp
$ npm run serve
Run Code Online (Sandbox Code Playgroud)
然后,我将vuetify插件添加到具有默认(推荐)预设的项目中:
cd testapp
vue add vuetify
Run Code Online (Sandbox Code Playgroud)
这给了我成功:
Installing vue-cli-plugin-vuetify...
+ vue-cli-plugin-vuetify@0.5.0
added 1 package from 1 contributor and audited 23942 packages in 9.235s
found 0 vulnerabilities
? Successfully installed plugin: vue-cli-plugin-vuetify
? Choose a preset: Default (recommended)
Invoking generator for vue-cli-plugin-vuetify...
Installing additional dependencies...
added 11 packages from 49 contributors and audited 23980 …Run Code Online (Sandbox Code Playgroud) 假设我正在托管site2.com并拥有site2.com/frame.html如下简单的文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Site2.com frame</title>
<style>
body { background-color: yellowgreen; }
</style>
</head>
<body id="site2-frame-body">
<h1>This is site2.com frame for 3rd party use</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在说 3rd 方网站site1.com想要通过这样的iframe元素嵌入这个内容:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Site1</title>
</head>
<body>
<style>
#site2frame { border: 2px solid red; }
#site2frame-body { background-color: blue !important; }
</style>
<iframe id="site2frame"
title="Inline Frame Example"
width="300" …Run Code Online (Sandbox Code Playgroud) 我正在使用Vuetify并尝试在v-text-field单击按钮时将文本从组件复制到剪贴板。Sample code available on codepen:
<template>
<div id="app">
<v-app id="inspire">
<v-container>
<v-text-field v-model="text1"></v-text-field>
<v-btn @click="copyText">copy</v-btn>
</v-container>
</v-app>
</div>
</template>
<script>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data() {
return {
text1: 'lorem ipsum 123'
}
},
methods: {
copyText (){
// copy to clipboard
}
}
})
</script>
Run Code Online (Sandbox Code Playgroud)
问题是copyText在Vue实例的方法中放什么代码?
我想在我的项目中使用 Vuetify 2.0,目前正在阅读有关v-stepper组件的信息,该组件用于通过编号步骤显示进度。
在提供的游乐场示例中,我看到他们正在使用<template>元素来包装v-stepper组件的内容。HTML 看起来像这样(注意:我删除了不必要的细节):
<v-stepper>
<template v-for="n in steps">
<v-stepper-content
:key="`${n}-content`"
:step="n"
>
</v-stepper-content>
</template>
</v-stepper>
Run Code Online (Sandbox Code Playgroud)
注意使用的<template>标签。它的目的是什么?我什么时候应该使用它而不是<v-stepper-content>直接将<v-stepper>?
我在 MDN 上阅读了一些关于element 的内容,但我不确定如何专门与 Vuetify 一起使用它(或者更一般地与 Vue.Js 或纯 HTML/CSS/JS 一起使用)。
我遇到了v-dialog组件的Vuetify示例,该示例 具有称为activator的作用域插槽,定义如下:
<template v-slot:activator="{ on }">
<v-btn
color="red lighten-2"
dark
v-on="on"
>
Click Me
</v-btn>
</template>
Run Code Online (Sandbox Code Playgroud)
我了解了VueJS文档中作用域插槽的用途以及解构插槽道具的概念,但我不理解v-on="on"此示例中的含义。特别是当未使用v-on指令指定事件时,这意味着什么?
在上VueJS文档v-on只能说明其在组合使用与事件名称明确指定(例如v-on:click="..."),但也没有只使用它作为解释v-on="..."。
有人可以在Vuetify示例中解释此语法及其用法吗?
Visual Studio Code 可以选择全局禁用扩展并仅对特定工作区启用它。
我想找出此设置保存在哪里,究竟是在哪个文件中?我检查过但找不到的位置是:
%APPDATA%\Code\User\settings.json.vscode/settings.json)%USERPROFILE%\.vscode\extensions有谁知道这个设置存储在哪里?
javascript ×6
vue.js ×6
vuetify.js ×4
html ×3
http ×2
asp.net-core ×1
browser ×1
c# ×1
cookies ×1
css ×1
iframe ×1
samesite ×1
vue-cli-3 ×1
vue-router ×1
vuejs2 ×1
vuex ×1