我正在练习这个例子。
https://github.com/kwmiebach/how-to-elixir-supervisor
我按照说明进行操作并了解其工作原理,但我无法理解 Supervisor、GenServer 和 Application 之间究竟有何不同。
有人可以解释这 3 种有何不同以及何时应该使用它们吗?
现在,我正在尝试创建一个网站,该网站显示由我的 NodeJS API 提供的最近的新闻帖子。
我尝试了以下方法:
HTML
<div id="news" class="media" v-for="item in posts">
<div>
<h4 class="media-heading">{{item.title}}</h4>
<p>{{item.msg}}</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
Javascript
const news = new Vue({
el: '#news',
data: {
posts: [
{title: 'My First News post', msg: 'This is your fist news!'},
{title: 'Cakes are great food', msg: 'Yummy Yummy Yummy'},
{title: 'How to learnVueJS', msg: 'Start Learning!'},
]
}
})
Run Code Online (Sandbox Code Playgroud)
显然,上面的方法不起作用,因为 Vue 无法渲染多个根元素。
我查了 VueJS 的官方手册,并没有想出一个解决方案。谷歌搜索一段时间后,我明白不可能渲染多个根元素,但是,我还没有想出一个解决方案。
这段代码给了我一个错误:
fn main() {
let x = [0 as u64; std::u64::MAX as usize];
println!("Hello, world! {}", std::u64::MAX);
}
Run Code Online (Sandbox Code Playgroud)
fn main() {
let x = [0 as u64; std::u64::MAX as usize];
println!("Hello, world! {}", std::u64::MAX);
}
Run Code Online (Sandbox Code Playgroud) 我正在用Vue建立我的第一个SPA项目.
我决定使用NodeJS作为后端,但是,我很难用JsonWebToken构建登录功能.
我写了一些代码来了解JWT是如何工作的,当我试图查看JWT如何验证时,服务器给了我一个错误.
JsonWebTokenError: jwt must be provided
at Object.module.exports [as verify] (c:\dir\node_modules\jsonwebtoken\verify.js:39:17)
at c:\projects\practice\demo\back\server.js:34:17
Run Code Online (Sandbox Code Playgroud)
下面是我的server.js的代码
这是导入内容的代码.
const express = require('express');
const jwt = require('jsonwebtoken');
const bodyParser = require('body-parser');
const api = express();
api.use(bodyParser.json());
api.use(bodyParser.urlencoded({ extended: true }));
Run Code Online (Sandbox Code Playgroud)
这是用于发布JWT的API.
api.post('/secure', function (req, res) {
const token = jwt.sign({ user: {id:1, name:'ME!', role: 'average'} }, 'dsfklgj');
console.log(token);
res.json({jwt: token});
});
Run Code Online (Sandbox Code Playgroud)
这是用于检查JWT的API.
api.post('/check/post', function (req, res) {
const token = req.body.jwt;
const x = jwt.verify(token, 'dsfklgj', function (err, decoded) {
if (err) …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Actix-Web 框架中使用Arc和实现共享状态Mutex。下面的代码可以编译,但是当我运行它时,计数器有时会一直回到 0。我如何防止这种情况发生?
use actix_web::{web, App, HttpServer};
use std::sync::{Arc, Mutex};
// This struct represents state
struct AppState {
app_name: String,
counter: Arc<Mutex<i64>>,
}
fn index(data: web::Data<AppState>) -> String {
let mut counter = data.counter.lock().unwrap();
*counter += 1;
format!("{}", counter)
}
pub fn main() {
HttpServer::new(|| {
App::new()
.hostname("hello world")
.register_data(web::Data::new(AppState {
app_name: String::from("Actix-web"),
counter: Arc::new(Mutex::new(0)),
}))
.route("/", web::get().to(index))
})
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
}
Run Code Online (Sandbox Code Playgroud) 我在前端使用nuxt,API 服务器使用phoenix/elixir,反向代理使用 nginx。
当我尝试制作用于上传文件的表单时,我遇到了麻烦。我如何与csrf?
以下代码产生结果-inf。
fn main() {
println!("{}", (-10. / 0.));
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试以下代码时,它没有打印出来true,而是给了我一个错误。
fn main() {
println!("{}", (-10. / 0.) == -inf);
}
Run Code Online (Sandbox Code Playgroud)
我应该给什么价值而不是-inf被true打印出来?
rust ×3
elixir ×2
actix-web ×1
ajax ×1
components ×1
express ×1
file-upload ×1
javascript ×1
jwt ×1
login ×1
math ×1
node.js ×1
nuxt.js ×1
vuejs2 ×1