所以目前我正与VueJS 2个工作,我感到非常新的吧。现在我得到了一些其他人的帮助,但我仍然陷入困境。Vuex和WebSockets的
这里就是我想实现(例如 - 紧扣我想要的):
- 我有一个应用程序的NodeJS上的WebSockets监听。应用程序通过WebSocket监听连接,并将采用JSON数据,然后使用命令,然后使用该命令需要的任何内容的数据对象。
例如该命令可以被登录,并且数据是用户名和密码。上的NodeJS应用程序的登录功能,然后将这些数据做什么需要,然后将其返回在插座,无论是成功还是失败,也许包括ID,并以皮卡和地方一些用户信息Vuex在它的状态,用于应用程序的前端拾取/使用。
目前我使用这种锅炉板:https://github.com/SimulatedGREG/electron-vue
这一直担任我很好的学习曲线,因为我想要使用的Vue和Vuex来管理我的应用程序,然后使用WebSockets进行数据管理并来自数据服务器。
所以,如果你看一下我在app/src目录/渲染/发送的链接(这是主要的代码是VUE和vuex)。
我的一个朋友加入如下代码我作为一个例子,我坚持努力让它进入vuex的行动和突变。他在一个vue组件中完成了所有的工作,所以我正在努力研究它如何与vuex协同工作。因为我希望能够从应用程序中的任何位置访问(示例)loginUser操作(使用多个页面/视图的路由)。
所以在MyApp/app/src/renderer/components/LandingPageView.vue
<template>
<div>
<img src="./LandingPageView/assets/logo.png" alt="electron-vue">
<h1>Welcome.</h1>
<current-page></current-page>
<websocket-output></websocket-output>
<versions></versions>
<links></links>
</div>
</template>
<script>
import CurrentPage from './LandingPageView/CurrentPage'
import Links from './LandingPageView/Links'
import Versions from './LandingPageView/Versions'
import WebsocketOutput from './LandingPageView/WebsocketOutput'
export default {
components: {
CurrentPage,
Links,
Versions,
WebsocketOutput
},
name: 'landing-page'
}
</script>
<style scoped>
img {
margin-top: -25px;
width: 450px;
}
</style>
这是更新后的文件,然后下面是针对MyApp/app/src/renderer/components/LandingPageView/WebsocketOutput.vue
<template>
<div>
<h2>Socket output:</h2>
<p v-text="socket_out"></p>
</div>
</template>
<script>
var ws = require("nodejs-websocket")
export default {
data() {
return {
socket_out: "connecting to the websocket server..."
}
},
mounted() {
const parent = this
var connection = ws.connect("ws://dannysmc.com:9999", {}, function (conn) {})
connection.on("text", function (text) {
console.log('Text received: ' + text)
parent.socket_out = text
})
connection.on("connect", function() {
connection.send('yo')
})
},
created() {
// Set $route values that are not preset during unit testing
if (process.env.NODE_ENV === 'testing') {
this.$route = {
name: 'websocket-output',
path: '/websocket-output'
}
}
}
}
</script>
<style scoped>
code {
background-color: rgba(46, 56, 76, .5);
border-radius: 3px;
color: #fff;
font-weight: bold;
padding: 3px 6px;
margin: 0 3px;
vertical-align: bottom;
}
p {
line-height: 24px;
color: red;
}
</style>
其他一切的代码只是你看到的锅炉板,所以如果有人愿意帮助我,给我一些关于解释这个或其他什么的解读技巧?因为不幸的是我无法找到很多信息。
为什么不直接设置您的插座以外的任何您的单个文件组件,而当你接收数据,分派到Vuex动作。如果你的组件正确设置,它们应该呈现新的状态。 – Bert
所以我会成立套接字说负载,那么当事件从插座发生,需要存储和做'store.dispatch()'? –
我不使用Vuex,但我有一个使用的WebSockets和本质是,在我的渲染器脚本创建WebSocket的,需要的存储,并成立了事件的WebSocket我这样它们直接调用储存的电子应用。 Vue只会在商店更改时呈现更改。 – Bert