基本上我想要一个最大长度为 4 的数组类型。很容易我无法找到如何在打字稿中实现此检查。有人可以帮我吗?像这样的东西:
const a = [item1, item2, item3, item4, *item5*] -> array has a maximum length of 4
Run Code Online (Sandbox Code Playgroud)
谢谢!
我有一个Vue组件,它使用引导网格。在子组件中,我想获取控制器中某个div的当前宽度。
这是子组件:
<template>
<div id="bg-prev" ref="prev">
<h1>{{x}}</h1>
</div>
<template>
export default {
props: ['section'],
data() {
return {
x: 0,
y: 0,
}
},
mounted() {
this.getWindowWidth();
},
methods: {
getWindowWidth() {
this.x = this.$refs.prev.clientWidth;
}
}
};
<style>
#bg-prev {
width: 100%;
}
</style>
Run Code Online (Sandbox Code Playgroud)
在此示例中,即使我检查该元素时具有清晰的宽度,该宽度也始终为0。我在这里缺少什么,已安装的挂钩是Vue生命周期中最新的挂钩?任何帮助表示赞赏;)
我尝试使用 Axios (和 VueJs)向我的 Rest Api (在本地主机上运行)发出跨源 POST 请求。它实际上没有执行 POST 请求,而是向我的 Rest Api 执行 OPTIONS 请求。这绕过了检查令牌并返回 403 的中间件函数。
这是登录功能
router.post('/login', (req, res) => {
User.authUser(req.body, (err, user) => {
var passwordIsValid = bcrypt.compareSync(req.body.password, user.password);
if (err) throw err;
if (!user) {
res.json({ success: false, message: 'User nicht gefunden' });
} else if (user) {
if (!passwordIsValid) {
res.json({ success: false, message: 'Falsches Passwort' });
} else {
const payload = {
admin: user.admin
};
var token = jwt.sign(payload, config.secret, { …Run Code Online (Sandbox Code Playgroud) 我正在使用Vue Router,而不是加载组件,它抛出了我这个模糊的错误:
Failed to mount component: template or render function not defined.
found in
---> <Anonymous>
<Root>
Run Code Online (Sandbox Code Playgroud)
这是我的入口点(app.js)(注意我正在使用多个条目与CommonsChunksPlugin结合):
import Vue from 'vue'
import '../../../assets/css/main.css'
import App from './app.vue'
new Vue(App).$mount('#app')
Run Code Online (Sandbox Code Playgroud)
Html文件(app.html)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0,
maximum-scale=1.0, user-scalable=0">
</head>
<body>
<div id="app"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
(app.vue)
<template>
<div>
<router-view></router-view>
</div>
</template>
<script>
import {
router,
} from './bootstrap.js';
export default {
router,
};
</script>
Run Code Online (Sandbox Code Playgroud)
路由器:
import Vue from 'vue';
import VueRouter from 'vue-router';
var routes …Run Code Online (Sandbox Code Playgroud) 我想改变我的阿波罗图QL客户端的默认头INSIDE一个反应成分,我根本不能设法找到的文档任何东西。因此,在我的 index.js 中,我按照描述创建并链接了我的客户端,并添加了一个 JWT 令牌标头。但是如果我想更改我的 React 组件中的标头怎么办。例如,我想在重新验证时替换令牌。
在 Axios 中,你可以简单地用它做一些事情。
axios.defaults.headers.common['Auth-Token'] = 'foo bar';
Run Code Online (Sandbox Code Playgroud)
我怎么能用 React Apollo 做这样的事情?这是我的 index.js 的重要部分
const httpLink = createHttpLink({
uri: 'https://somesecureapi',
});
const authLink = setContext((_, { headers }) => {
const token = localStorage.getItem('token');
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : "",
}
}
});
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache()
});
Run Code Online (Sandbox Code Playgroud)
我尝试导出客户端,然后将其导入组件创建一个新链接并更改旧链接,但这不起作用。
必须有一些更简单的方法。有什么建议
javascript ×3
vue.js ×3
vuejs2 ×2
apollo ×1
arrays ×1
axios ×1
express ×1
graphql ×1
reactjs ×1
redux ×1
rest ×1
typescript ×1
vue-router ×1
webpack ×1