|
3 | 3 | <div class="wrapper">
|
4 | 4 | <section class="mqtt-fields">
|
5 | 5 | <div class="field-view">
|
6 |
| - <div data-step="1" data-intro="Step 1: Connect or disconnect to the MQTT broker! 🔗 "> |
7 |
| - <button class="mqtt-button connect" @click="$mqtt.connect()"> |
| 6 | + <div |
| 7 | + data-step="1" |
| 8 | + data-intro="Step 1: Connect or disconnect to the MQTT broker! 🔗 " |
| 9 | + > |
| 10 | + <button class="mqtt-button connect" @click="handleClick()"> |
8 | 11 | CONNECT
|
9 | 12 | </button>
|
10 | 13 | <button class="mqtt-button disconnect" @click="$mqtt.disconnect()">
|
11 | 14 | DISCONNECT
|
12 | 15 | </button>
|
13 |
| - <span>MQTT status: <label> {{ $mqtt.status() }} </label></span> |
| 16 | + <span |
| 17 | + >MQTT status: <label> {{ $mqtt.status() }} </label></span |
| 18 | + > |
14 | 19 | </div>
|
15 | 20 | <div class="hr" />
|
16 |
| - <div class="settings" data-step="2" |
17 |
| - data-intro="Step 2: Configure & update the client settings! <i>(changes will apply on reconnect)</i> ⚙️"> |
| 21 | + <div |
| 22 | + class="settings" |
| 23 | + data-step="2" |
| 24 | + data-intro="Step 2: Configure & update the client settings! <i>(changes will apply on reconnect)</i> ⚙️" |
| 25 | + > |
18 | 26 | <span class="field-row">
|
19 | 27 | <span>Host:</span>
|
20 | 28 | <input placeholder="enter mqtt host" v-model="host" />
|
|
30 | 38 | <span class="field-row">
|
31 | 39 | <span>Use SSL:</span>
|
32 | 40 | <select class="optionField" v-model="useSSL">
|
33 |
| - <option :key="index" v-for="(option, index) in sslOptions" :value="option"> |
| 41 | + <option |
| 42 | + :key="index" |
| 43 | + v-for="(option, index) in sslOptions" |
| 44 | + :value="option" |
| 45 | + > |
34 | 46 | {{ option }}
|
35 | 47 | </option>
|
36 | 48 | </select>
|
|
41 | 53 | </span>
|
42 | 54 | <span class="field-row">
|
43 | 55 | <span>Password:</span>
|
44 |
| - <input placeholder="enter mqtt password" v-model="password" type="password"/> |
| 56 | + <input |
| 57 | + placeholder="enter mqtt password" |
| 58 | + v-model="password" |
| 59 | + type="password" |
| 60 | + /> |
45 | 61 | </span>
|
46 | 62 | <span class="field-row">
|
47 | 63 | <span>Main Topic:</span>
|
|
56 | 72 | </button>
|
57 | 73 | </div>
|
58 | 74 | <div class="hr" />
|
59 |
| - <div class="settings" data-step="4" |
60 |
| - data-intro="Step 4: Enter the topic, payload,and select the QoS mode and click publish! 📦"> |
61 |
| - <div style=" |
| 75 | + <div |
| 76 | + class="settings" |
| 77 | + data-step="4" |
| 78 | + data-intro="Step 4: Enter the topic, payload,and select the QoS mode and click publish! 📦" |
| 79 | + > |
| 80 | + <div |
| 81 | + style=" |
62 | 82 | font-weight: bold;
|
63 | 83 | font-size: 20px;
|
64 | 84 | margin-bottom: -15px;
|
65 | 85 | margin-top: -15px;
|
66 |
| - "> |
| 86 | + " |
| 87 | + > |
67 | 88 | Publish Data
|
68 | 89 | </div>
|
69 | 90 | <span>
|
|
73 | 94 | <span class="field-row">
|
74 | 95 | <span>Publish Mode: </span>
|
75 | 96 | <select style="margin: -15px 0" v-model="pubMode">
|
76 |
| - <option v-bind:key="option.value" v-for="option in options" v-bind:value="option.value"> |
| 97 | + <option |
| 98 | + v-bind:key="option.value" |
| 99 | + v-for="option in options" |
| 100 | + v-bind:value="option.value" |
| 101 | + > |
77 | 102 | {{ option.text }}
|
78 | 103 | </option>
|
79 | 104 | </select>
|
80 | 105 | </span>
|
81 |
| - <button class="pub" @click="$mqtt.publish(pubTopic, pubData, pubMode as MqttMode)"> |
| 106 | + <button |
| 107 | + class="pub" |
| 108 | + @click="$mqtt.publish(pubTopic, pubData, pubMode as MqttMode)" |
| 109 | + > |
82 | 110 | Publish
|
83 | 111 | </button>
|
84 | 112 | </div>
|
85 | 113 | <div class="hr" />
|
86 | 114 | <button class="unsub" @click="unsubAll()">Unsubscribe All</button>
|
87 | 115 | <div class="hr" />
|
88 | 116 | <span class="field-row">
|
89 |
| - <img src="https://cdn-icons-png.flaticon.com/512/25/25231.png" height="25" alt="github" /> |
90 |
| - <a href="https://github.com/kaandesu/vue-paho-mqtt/" target="_blank" rel="noopener noreferrer" |
91 |
| - style="font-size: 15px; font-weight: bold"><i>kaandesu/vue-paho-mqtt</i></a> |
| 117 | + <img |
| 118 | + src="https://cdn-icons-png.flaticon.com/512/25/25231.png" |
| 119 | + height="25" |
| 120 | + alt="github" |
| 121 | + /> |
| 122 | + <a |
| 123 | + href="https://github.com/kaandesu/vue-paho-mqtt/" |
| 124 | + target="_blank" |
| 125 | + rel="noopener noreferrer" |
| 126 | + style="font-size: 15px; font-weight: bold" |
| 127 | + ><i>kaandesu/vue-paho-mqtt</i></a |
| 128 | + > |
92 | 129 | <button class="help" @click="startIntro()">?</button>
|
93 | 130 | </span>
|
94 | 131 | </div>
|
95 | 132 | </section>
|
96 |
| - <section class="subview" data-step="3" |
97 |
| - data-intro="Step 3: Enter a topic you want to subscribe to, and click subscribe! You can subscribe multiple topics at once! <i>On the bottom of the card you can see the data arrived!</i> 👀"> |
| 133 | + <section |
| 134 | + class="subview" |
| 135 | + data-step="3" |
| 136 | + data-intro="Step 3: Enter a topic you want to subscribe to, and click subscribe! You can subscribe multiple topics at once! <i>On the bottom of the card you can see the data arrived!</i> 👀" |
| 137 | + > |
98 | 138 | <div v-for="(card, index) in subList" :key="index" class="sub-card">
|
99 | 139 | <input placeholder="enter topic name" v-model="card.topic" />
|
100 | 140 | <div class="button-section">
|
101 | 141 | <div class="row">
|
102 |
| - <button :disabled="card.topic == ''" @click="subscribe(card.topic, index)" class="btn"> |
| 142 | + <button |
| 143 | + :disabled="card.topic == ''" |
| 144 | + @click="subscribe(card.topic, index)" |
| 145 | + class="btn" |
| 146 | + > |
103 | 147 | Subscribe
|
104 | 148 | </button>
|
105 |
| - <button :disabled="card.topic == ''" @click=" |
106 |
| - $mqtt.unsubscribe(card.topic); |
107 |
| - card.subData = '---'; |
108 |
| - " class="btn"> |
| 149 | + <button |
| 150 | + :disabled="card.topic == ''" |
| 151 | + @click=" |
| 152 | + $mqtt.unsubscribe(card.topic); |
| 153 | + card.subData = '---'; |
| 154 | + " |
| 155 | + class="btn" |
| 156 | + > |
109 | 157 | Unsubscribe
|
110 | 158 | </button>
|
111 | 159 | </div>
|
|
115 | 163 | </section>
|
116 | 164 | </div>
|
117 | 165 | <div class="title">
|
118 |
| - <img :class="$mqtt.status() === 'connected' ? '' : 'img-red'" src="/assets/logo.png" height="100" |
119 |
| - alt="Vue-Paho-Mqtt-Logo" /> |
| 166 | + <img |
| 167 | + :class="$mqtt.status() === 'connected' ? '' : 'img-red'" |
| 168 | + src="/assets/logo.png" |
| 169 | + height="100" |
| 170 | + alt="Vue-Paho-Mqtt-Logo" |
| 171 | + /> |
120 | 172 | <h3>Vue Paho Mqtt Plugin - Live Demo</h3>
|
121 | 173 | </div>
|
122 | 174 | </main>
|
@@ -164,6 +216,14 @@ const subscribe = (topic: string, index: number) => {
|
164 | 216 | });
|
165 | 217 | };
|
166 | 218 |
|
| 219 | +const handleClick = async () => { |
| 220 | + try { |
| 221 | + await $mqtt.connect(); |
| 222 | + } catch (e) { |
| 223 | + console.error('test error:', e); |
| 224 | + } |
| 225 | +}; |
| 226 | +
|
167 | 227 | const updateAll = () => {
|
168 | 228 | $mqtt.host(host.value);
|
169 | 229 | $mqtt.port(parseInt(port.value));
|
@@ -316,7 +376,7 @@ onMounted(() => {
|
316 | 376 | /* Firefox */
|
317 | 377 | }
|
318 | 378 |
|
319 |
| -span>label { |
| 379 | +span > label { |
320 | 380 | font-size: 17px;
|
321 | 381 | font-weight: bold;
|
322 | 382 | }
|
|
0 commit comments