小编une*_*asy的帖子

JavaScript Promises 混淆反模式?

我花了一整天的时间试图弄清楚我错误地使用了 Promise 的天气。

那是反模式吗?

export const myExample = (payload) => {
  return new Promise((resolve, reject) => {})
}
Run Code Online (Sandbox Code Playgroud)

我可以像这样在承诺中使用异步吗?

export const myExample = (payload) => {
  return new Promise(async (resolve, reject) => {})
}
Run Code Online (Sandbox Code Playgroud)

这也是错的吗?假设添加 async 使其成为默认的承诺,

export const myExample = async (payload) => {
  return new Promise((resolve, reject) => {})
}
Run Code Online (Sandbox Code Playgroud)

如果是这种情况,我是否应该只从与解析相同的函数返回,如果我抛出错误将被拒绝,所以它看起来像那样?

export const myExample = async (payload) => {
  if(payload) return true
  else throw new Error('Promise rejection?')
}
Run Code Online (Sandbox Code Playgroud)

那么 first 和 last 是一样的吗?

javascript promise

7
推荐指数
1
解决办法
148
查看次数

CSS位置粘性,重叠而不是推动

我很难理解为什么粘性 div 不推送其他粘性 div。我很确定我已经看到它是这样工作的,但我无法弄清楚。

我希望标头 1 推动标头 2,而不是重叠在其上。超文本标记语言

<div class="header">
  <h1>Header 1</h1>
</div>

<div class="item">
  <h1>Item1</h1>
</div>

<div class="item">
  <h1>Item2</h1>
</div>

<div class="header">
  <h1>Header 2</h1>
</div>

<div class="item">
  <h1>Item1</h1>
</div>

<div class="item">
  <h1>Item2</h1>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

h1 {
  text-align: center;
  color: #000;
  font: bold 20vw Helvetica, Arial, sans-serif;
}

.header {
  position: sticky;
  top: 0px;
  height: 100%;
  width: 100%;
  background: white;
}
.item {
  height: 100vh;
  width: 100%;
  background: #00f;
}
Run Code Online (Sandbox Code Playgroud)

这是一个例子以及我正在尝试做的事情。 …

html css sticky

4
推荐指数
1
解决办法
3121
查看次数

VueJs (Quasar)、vuex 在路由器中存储访问

我正在尝试学习 Vuex 并制作身份验证模块。我正在遵循一些教程,直到我想在路由器中使用存储时。我正在路由器index.js的顶部导入我的商店,但是我猜测它没有导入我的商店,因为我无法访问例如getter(未定义)。

Store 在 vue 组件中运行良好。为什么会这样?是因为创建路由器时存储没有正确初始化吗?按照教程,效果很好。

路由器/index.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import store from '../store'
Vue.use(VueRouter)

/*
 * If not building with SSR mode, you can
 * directly export the Router instantiation
 */

export default function(/* { store, ssrContext } */) {
  const Router = new VueRouter({
    scrollBehavior: () => ({ x: 0, y: 0 }),
    routes,
    // Leave these as is and change from quasar.conf.js instead!
    // quasar.conf.js -> build …
Run Code Online (Sandbox Code Playgroud)

javascript router store vue.js vuex

2
推荐指数
1
解决办法
4026
查看次数

标签 统计

javascript ×2

css ×1

html ×1

promise ×1

router ×1

sticky ×1

store ×1

vue.js ×1

vuex ×1