我有一个AWS api代理lamba函数.我目前使用不同的端点和单独的lambda函数:
api.com/getData --> getData
api.com/addData --> addData
api.com/signUp --> signUp
Run Code Online (Sandbox Code Playgroud)
管理所有端点和功能的过程变得很麻烦.当我将一个端点用于一个lambda函数时,是否有任何缺点,该函数根据查询字符串决定做什么?
api.com/exec&func=getData --> exec --> if(params.func === 'getData') { ... }
Run Code Online (Sandbox Code Playgroud) 我需要将接口属性映射到对象:
interface Activity {
id: string,
title: string,
body: string,
json: Object
}
Run Code Online (Sandbox Code Playgroud)
我目前这样做:
headers: Array<Object> = [
{ text: 'id', value: 'id' },
{ text: 'title', value: 'title' },
{ text: 'body', value: 'body' },
{ text: 'json', value: 'json' }
]
Run Code Online (Sandbox Code Playgroud)
这变得非常重复.我想要的是这样的:
headers: Array<Object> = Activity.keys.map(key => {
return { text: key, value: key }
})
Run Code Online (Sandbox Code Playgroud) 我可以使用类型提示允许两种不同的类型吗?例如,参数1可以是2个类
function log (User|File $requester) {
}
Run Code Online (Sandbox Code Playgroud) 我在我的EC2实例上运行一个服务,我想设置一个只允许我的lambda函数访问它的入站规则.安全组允许我限制特定IP的访问,但我不认为lambda函数具有指定的特定IP.有办法做我想要的吗?
我有一个静态方法的类:
class User {
constructor() {
User.staticMethod();
}
static staticMethod() {}
}
Run Code Online (Sandbox Code Playgroud)
对于静态方法是否有这样的东西(即引用没有实例的当前类).
this.staticMethod()
Run Code Online (Sandbox Code Playgroud)
所以我不必写类名'User'.
我想通过分配setter方法mapState.我目前使用一种解决方法,我将我感兴趣的变量命名为(todo)作为临时名称(storetodo),然后在另一个计算变量中引用它todo.
methods: {
...mapMutations([
'clearTodo',
'updateTodo'
])
},
computed: {
...mapState({
storetodo: state => state.todos.todo
}),
todo: {
get () { return this.storetodo},
set (value) { this.updateTodo(value) }
}
}
Run Code Online (Sandbox Code Playgroud)
我想跳过额外的步骤并直接在其中定义getter,setter mapState.
我为什么要这样做?
正常的方法是使用mapMutations/ mapActions&mapState/ mapGetters
没有我上面说明的计算的get/set组合,并直接在HTML中引用变异:
<input v-model='todo' v-on:keyup.stop='updateTodo($event.target.value)' />
Run Code Online (Sandbox Code Playgroud)
getter/setter版本允许我简单地写:
<input v-model='todo' />
Run Code Online (Sandbox Code Playgroud) $start = '22:00:00';
$end = '08:00:00';
$now = Carbon::now('UTC');
Run Code Online (Sandbox Code Playgroud)
如何检查 $now 的时间是否在时间范围内?
是否有可能订阅个别突变?
代替:
this.$store.subscribe((mutation, state) => {
if(mutation === 'someMutation'){
doSomething()
}
})
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
this.$store.subscribe('someMutation', state => {
doSomething()
})
Run Code Online (Sandbox Code Playgroud) 我见过很多人建议通过props将状态传递给组件,而不是直接访问组件内部的vue状态,以使其更具可重用性.
但是,如果我一直这样做,这意味着只有路由根组件才能与商店通信,并且所有数据都需要通过嵌套层次结构传递才能获得最终组件.这似乎很容易造成混乱:
Dashboard
Profile
Billing
History
CreditCards
CreditCard
Run Code Online (Sandbox Code Playgroud)
如何为用户信用卡加载数据?在仪表板中将它一直传递到树下?
我想在onMessage监听器中使用async await:
chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) =>{
var key = await getKey();
sendResponse(key);
});
Run Code Online (Sandbox Code Playgroud)
但是当我发送消息时,我得到了不确定.
从chrome.runtime.onMessage.addListener的文档中:
当事件侦听器返回时,此函数变为无效,除非您从事件侦听器返回true以指示您希望异步发送响应(这将使消息通道保持打开到另一端,直到调用sendResponse).
这在我使用回调时有效.
chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) =>{
getKey(key => {
sendResponse(key);
});
return true;
});
Run Code Online (Sandbox Code Playgroud)
但是我想利用await语法.但它似乎没有工作,仍然返回undefined:
chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) =>{
var key = await getKey();
sendResponse(key);
return true;
});
Run Code Online (Sandbox Code Playgroud) javascript ×4
vue.js ×3
vuex ×3
aws-lambda ×2
php ×2
api ×1
async-await ×1
class ×1
php-8 ×1
php-carbon ×1
static ×1
this ×1
type-hinting ×1
typescript ×1