我在理解如何检查上下文是否超出超时设置的截止日期时遇到麻烦,或者我是否应该检查所有内容?
这是mongo-go-driver的片段:
client, err := NewClient("mongodb://foo:bar@localhost:27017")
if err != nil { return err }
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
err = client.Connect(ctx)
if err != nil { return err }
Run Code Online (Sandbox Code Playgroud)
阅读此代码,我如何知道上下文是否超过了期限?从我天真的理解(或不理解)的角度来看,该行err = client.Connect(ctx)会给我错误,包括超过了截止日期(如果超过了),因此我认为我什至不需要显式检查?
但是,然后在四处浏览互联网以更好地了解上下文如何工作时,我遇到了一些选择情况的用法,这些情况明确地检查了以下情况(来自http://p.agnihotry.com/post/understanding_the_context_package_in_golang/的代码段):
//Use a select statement to exit out if context expires
select {
case <-ctx.Done():
fmt.Println("sleepRandomContext: Time to return")
case sleeptime := <-sleeptimeChan:
//This case is selected when processing finishes before the context is cancelled
fmt.Println("Slept for ", sleeptime, "ms")
} …Run Code Online (Sandbox Code Playgroud) 我有一个使用vue cli 3创建的项目。当我运行命令“ npm run serve”时,它会显示以下成功消息(我用假#替换了我的IP地址):
App running at:
- Local: http://localhost:8080/
- Network: http://1.2.3.4:8080/
Run Code Online (Sandbox Code Playgroud)
在我自己的计算机上,一切正常。在我自己的计算机上,我既可以通过本地地址访问,也可以通过IP地址访问,但是无法使用连接到同一wifi网络的其他设备上的网络地址访问。
我尝试了以下方法:
On vue.config.js:
devServer: {
host: '0.0.0.0'
}
and
devServer: {
open: process.platform === 'darwin',
host: '0.0.0.0',
port: 8080,
https: false,
hotOnly: false
}
on my package.json:
"scripts": {
"serve": "vue-cli-service serve --host 0.0.0.0",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
}
and
"scripts": {
"serve": "vue-cli-service serve --host 0.0.0.0 --allowed-hosts 1.2.3.4",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
}
Run Code Online (Sandbox Code Playgroud)
我的tomcat服务器运行在端口80上,并且在我的计算机和其他设备上都可以正常工作...
这是我遇到的错误页面:
如何做到这一点,以便可以从同一网络上的其他设备访问我的vue项目?
感谢您的时间和帮助!
我知道这似乎是一个重复的问题,在尝试以下操作后,我仍然遇到这种类型的 eslint 错误:
https://github.com/prettier/prettier/issues/3720 (我已经安装了 eslint-plugin-vue)
Vue.js eslint 解析错误。:意外令牌(与我的问题并不真正相关,但我还是尝试了)
这是我的 package.json 设置的一部分:
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.5",
"@vue/cli-plugin-eslint": "^3.0.5",
"@vue/cli-plugin-unit-jest": "^3.0.5",
"@vue/cli-service": "^3.0.5",
"@vue/eslint-config-airbnb": "^4.0.0",
"@vue/test-utils": "^1.0.0-beta.20",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"eslint": "^5.8.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-vue": "^5.0.0-0",
"vue-template-compiler": "^2.5.17"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"@vue/airbnb"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint",
"ecmaVersion": 6
}
},
Run Code Online (Sandbox Code Playgroud)
这是我的.eslintrc.js文件:
module.exports = …Run Code Online (Sandbox Code Playgroud) eslint vue.js airbnb-js-styleguide eslint-config-airbnb vue-cli-3