我正在为 vue 应用程序开发自动保存功能,每次对 vue 应用程序数据进行更改时都会将数据发送到 api。使用 vue watch 时是否可以忽略对象的某些属性?该对象有多个值,我想监视这些值以自动保存,并且只有 1 或 2 个值会被忽略,因此为我想要的所有属性设置监视函数似乎没有意义,而是忽略 1我不。
这是数据的基本结构:
data:{
template: {
name: "Template",
id: 1,
variables: [
{
name: "v1",
color: "#fff",
group: 1,
isSelected: true
},
{
name: "v2",
color: "#fff",
group: 3,
isSelected: false
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
以及基本的手表功能:
watch: {
template: {
handler: function(){
this.save();
},
deep: true
}
}
Run Code Online (Sandbox Code Playgroud)
模板中变量的 isSelected 字段仅用于 UI 目的,我希望手表忽略该字段的更改,因为它们不会被保存。我不想为变量中的每个字段设置一个监视函数,而是在监视中执行以下操作:
ignore: "template.variables.isSelected"
Run Code Online (Sandbox Code Playgroud) 我正在开发一个报告构建工具,该工具从 Facebook Graph Api 中提取数据以显示广告帐户中的广告指标。当我从帐户级别提取所有见解时,像素购买价值明显低于 Facebook 商务管理平台中显示的价值。
查询:
{act_id}/insights?fields=spend,action_values,website_purchase_roas&date_preset=this_month
Run Code Online (Sandbox Code Playgroud)
它返回以下数据:
"spend": "5037.47",
"action_values": [
{
"action_type": "offsite_conversion.custom",
"value": "16049.98"
}
],
"website_purchase_roas": [
{
"action_type": "offsite_conversion.fb_pixel_purchase",
"value": "3.186119"
}
]
Run Code Online (Sandbox Code Playgroud)
但业务经理显示的像素购买价值为 17,315.53 美元,网站 roas 为 3.44。支出值似乎是实时更新的,有时甚至比商务管理器页面的更新速度还要快。
Insights 边缘是否还有其他一些值字段显示更多购买,或者这是 Facebook api 中的错误?
facebook facebook-graph-api facebook-ads-api facebook-marketing-api
我有一个模型画板和一个模型组,它们通过名为 ArtboardsGroups 的表具有多对多关系,该表具有与该关系相关的 x 和 y 值的属性
class Artboard < ApplicationRecord
has_many :artboards_groups, dependent: :destroy
has_many :groups, -> { select("groups.id as id, groups.name as name, artboards_groups.x as x, artboards_groups.y as y, artboards_groups.index as index, artboards_groups.r as r") }, through: :artboards_groups
end
class ArtboardsGroup < ApplicationRecord
belongs_to :artboard
belongs_to :group
end
class Group < ApplicationRecord
has_many :artboards_groups, dependent: :destroy
has_many :artboards, through: :artboards_group
end
Run Code Online (Sandbox Code Playgroud)
当我尝试单独访问它时,该模型工作得很好,但是当我尝试通过画板选择组并访问“y”属性时,我收到一个错误,它是私有方法
NoMethodError: private method `y' called for #<Group id: 5, name: nil>
Run Code Online (Sandbox Code Playgroud)
根据这个线程(10多年前),这是因为ActiveRecord::Base 中有一个名为 …
我正在开发一个应用程序,该应用程序会阻止用户访问除主页和注册之外的任何页面,除非他们已登录。我有一个包罗万象的路由防护,可以在尝试访问页面时检查用户是否已登录并重定向到如果返回 false 则登录。在登录组件中,用户登录后,他们将被定向到主页。我想要设置的是,当用户登录时,如果他们之前访问过某个页面或直接输入了页面的 url,则重定向到应用程序的最后一个页面,如果没有重定向到主页。例如:
用户导航到 my.app/{somePage} -> 路由防护检查登录返回 false -> 重定向到 my.app/sigin -> 用户成功登录 -> 重定向到 my.app/{somePage}
//Route Guard
router.beforeEach((to, from, next) => {
if(!signedIn()){
router.replace('/signin')
}
else{
next()
}
})
//Successful signin
signInSuccess(){
//Want this to redirect to intended page if exists
this.$router.replace('/')
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用 this.$router.go(-1) 进行重定向,但是当我重定向到路由防护中的登录页面时,预期的路由似乎没有被推入历史记录中。
我还尝试在 vuex 商店中设置状态以捕获预期路线并在登录后使用它进行重定向,但路线防护似乎会重新加载整个页面,因此商店状态会重置。
我唯一能想到的另一件事是将预期的页面路由存储在浏览器本地存储中,但这似乎不是一个可靠的解决方案。