似乎Vue Meta已升级为使用名为的新 npm 包处理 Vue.js 3vue-3-meta
在 Vue.js 3 之前,vue-meta通过将其添加到 Vue 实例中很容易使用:
import Vue from 'vue'
import VueMeta from 'vue-meta'
Vue.use(VueMeta, {
// optional pluginOptions
refreshOnceOnNavigation: true
})
Run Code Online (Sandbox Code Playgroud)
但是在 Vue.js 3 中,没有 Vue 实例;而是通过运行createApp这样的方式来创建应用程序:
const app = createApp(App);
const router = createVueRouter();
app.use(router);
// need to make app use Vue-Meta here
Run Code Online (Sandbox Code Playgroud)
我找不到任何文档vue-3-meta。import VueMeta from 'vue-meta'不再有效。
如何vue-3-meta正确导入插件并将其与app之前版本中的一样使用?
我正在使用express-validator来验证表单,但许多字段是可选的。我已经在我的路线上配置了验证器,如下所示:
const ExpValidate = require('express-validator');
router.post('/api/posthandler',
[ ExpValidate.body("TopicID").optional({nullable: true, checkFalsy: true}).trim().isInt(), ]
async function(req, res) {
const errors = ExpValidate.validationResult(req);
if (!errors.isEmpty()) {
return res.status(422).json({ errors: errors.array() });
}
else {
// Handle form here
}
Run Code Online (Sandbox Code Playgroud)
当使用 提交表单时TopicID: null,我收到一条错误消息:
{
"errors": [
{
"value": "null",
"msg": "Invalid value",
"param": "TopicID",
"location": "body"
}
]
}
Run Code Online (Sandbox Code Playgroud)
即使我{nullable: true, checkFalsy: true}从optional()方法中删除选项,我也会收到相同的错误。
如果我这样做,我不会收到任何错误,ExpValidate.body("TopicID").optional()但这违背了验证器检查isInt()是否提供了值的目的。
TopicID如果我根本不提交,那么我也不会收到任何错误。
我的配置有问题吗?
更新:虽然这个问题是不久前出现的,但发生的情况是表单数据将所有内容作为字符串发送。所以null …
我在 Vue 组件中实现了一个watch显示产品信息的组件。手表的watch对象为routevue-routerProductID。当它发生变化时,我想从后端API获取产品详细信息。
为了观看route,我这样做Product.vue:
import { useRoute } from 'vue-router'
export default {
setup() {
const route = useRoute();
async function getProduct(ProductID) {
await axios.get(`/api/product/${ProductID}`).then(..do something here)
}
// fetch the product information when params change
watch(() => route.params.ProductID, async (newID, oldID) => {
await getProduct(newId)
},
//watch options
{
deep: true,
immediate: true
}
)
},
}
Run Code Online (Sandbox Code Playgroud)
上面的代码有效,但如果用户离开Product.vue,例如使用后退按钮返回主页,则会watch再次触发 并尝试使用undefinedProductID 调用 API(因为参数 …
我试图Form根据另一个名为的反应变量中的数据设置 a 的值Product,但它似乎不起作用。如果数据可用,则应Form将其值设置为数据,如果不可用,则只需使用。Productnull
这是vue组件代码的一部分:
props: {
ProductID: {
type: Number,
default: null
}
},
setup (props) {
const Product = ref();
async function loadProduct(ProductID) { // Runs when `props.ProductID` changes using a watcher
try {
const Response = await $axios.get(`/api/product/${ProductID}`);
Product.value = Response.data; // This is an array of data
} catch (error) {
console.log(error);
}
}
}
const Form = ref({
ProductTitle: Array.isArray(Product.value) && Product.value[0].producttitle ? Product.value[0].producttitle : null,
ProductText: Array.isArray(Product.value) …Run Code Online (Sandbox Code Playgroud) 我在<cfoutput>整个<html>标签周围放置了一个标签.ColdBox最佳实践指南指出"当您创建视图模板时,请尝试始终使用1 cfoutput标记将其包围,而不是将它们嵌套在整个地方."
但我偶尔会看到错误弹出,其中<script>包含javascript代码的块在<cfoutput>标记内.这可能是因为Coldfusion看到一个哈希#并尝试解析它,但它不能因为它的javascript.
那么如何<cfoutput>在视图页面上放置一个标记来放置所有内容呢?
URLEncodedFormat() 函数执行我特别想要的操作,即:
生成 URL 编码的字符串。例如,它将空格替换为 %20
为什么 EncodeForURL() 不这样做?它用加号“+”符号替换空格,这会阻止我的 URL 工作。
除了使用 URLEncodedFormat() 之外,我还能如何解决这个问题?
我目前正在使用<cfinvoke>标签来调用CFC并传递它们的参数.这非常方便,因为我可以使用标签仅传入我想要的参数:
<cfinvoke component="pathtofolder.imagehandler" method="SomeMethod" argumentcollection="#VARIABLES#" returnvariable="ImageHandlerResult">
<cfif structkeyexists(ARGUMENTS, 'Argument1')>
<cfinvokeargument name="Parameter1" value="#ARGUMENTS.Argument1#" />
</cfif>
<cfif structkeyexists(ARGUMENTS, 'Argument2')>
<cfinvokeargument name="Parameter2" value="#ARGUMENTS.Argument2#" />
</cfif>
<cfif structkeyexists(ARGUMENTS, 'Argument3')>
<cfinvokeargument name="Parameter3" value="#ARGUMENTS.Argument3#" />
</cfif>
</cfinvoke>
<cfreturn ImageHandlerResult /> <!--- how do you get this using createObject/new method? --->
Run Code Online (Sandbox Code Playgroud)
如果我使用new()或createObject()方法创建CFC的实例,然后在这个新创建的实例中调用方法,我无法有条件地传递参数.我在运行时遇到错误.
<cfset ImageHandler = new pathtofolder.imagehandler()/>
<cfset ImageHandler.SomeMethod(
<cfif StructKeyExists(ARGUMENTS, 'Argument1')>
Parameter1 = ARGUMENTS.Argument1
</cfif>
<cfif StructKeyExists(ARGUMENTS, 'Argument2')>
Parameter2 = ARGUMENTS.Argument2
</cfif>
<cfif StructKeyExists(ARGUMENTS, 'Argument3')>
Parameter3 = ARGUMENTS.Argument3
</cfif>
)/> …Run Code Online (Sandbox Code Playgroud) 我正在管理使用 执行登录和登录状态Vuex。这是一个标准程序:
Vuex操作,以使用凭据axios对 Node/Express 端点进行 API 调用/api/loginstate.user如果成功,API 的响应将发回通过突变存储在对象中的用户数据setUser。标志state.user.isLoggedIn也设置为true。以上一切都按预期工作。但是,如果用户刷新浏览器,则Vuex状态会被清空,并且站点标题不再显示用户信息。为了克服这个问题,我将其作为持久数据存储state.user在localStorage浏览器中,并使用页面刷新Vuex中的数据重新填充存储。localStorage如果用户注销,则被localStorage清除。
有很多路由需要检查用户是否登录。我不能依赖,localStorage因为它可以由用户操纵。如果用户删除包含 JWT 的 cookie,则该 cookielocalStorage不会被清空,并且站点标头仍会显示其登录信息。因此,我需要在几乎每个页面上执行 API 调用来检查用户是否已登录,如果没有则将其删除localStorage。
我的问题是:
app安装 Vue 时还是在vue-router使用beforeEach导航卫士时发生?beforeEachin ,每次用户更改路线vue-router时都会通过 API 调用来使网站崩溃吗?/api/login在每条路线上都这样做是正常做法吗?我有一个单独的表单,可以向人们发送电子邮件.有两个按钮可以执行此操作:新建和回复.
readonly到主题字段.但是,如果有人点击"回复"然后改变主意实际发送新电子邮件,则表示我已丢失表单的所有默认值和属性.我无法手动输入这些值,因为值是动态来自数据库的.
我无法理解如何在页面上切换新建和回复.我猜我可以在有人点击New时重新加载页面,但这是唯一的方法吗?
编辑:
我应该提到我还需要重置隐藏字段的值.当我说"重置"时,我的意思是回到原来的价值......不清楚value属性.
我发现这篇文章解释了在 SP 中使用 IF/ELSE 语句可能会导致性能下降,而不是为每个“分支”使用单独的 SP。http://sqlmag.com/t-sql/if-statements-and-stored-procedure-performance
但我有一个 SP,它从相同的表中选择相同的列,并且只有 WHERE 子句根据存在的变量而变化。这是一个例子:
IF @Variable1 IS NOT NULL
BEGIN
SELECT
*
FROM
dbo.Table1
WHERE
Column1 = @Variable1
END
ELSE IF @Variable1 IS NULL AND @Variable2 IS NOT NULL
BEGIN
SELECT
*
FROM
dbo.Table1
WHERE
Column1 = Column1
AND
Column2 = @Variable2
END
Run Code Online (Sandbox Code Playgroud)
那么在这个例子中,是用 2 个独立的 SP 来处理不同的变量更好,还是像这样将所有的 SP 都放在一个 SP 中更好?(我知道使用SELECT *不是一个好的做法。我只是为了举例而这样做)
vue.js ×4
vuejs3 ×4
coldfusion ×3
javascript ×2
vue-router ×2
cfc ×1
express ×1
jquery ×1
node.js ×1
sql ×1
sql-server ×1
vue-meta ×1
vuex ×1