link1233 link1234 link1235 link1236 link1237 link1238 link1239 link1240 link1241 link1242 link1243 link1244 link1245 link1246 link1247 link1248 link1249 link1250 link1251 link1252 link1253 link1254 link1255 link1256 link1257 link1258 link1259 link1260 link1261 link1262 link1263 link1264 link1265 link1266 link1267 link1268 link1269 link1270 link1271 link1272 link1273 link1274 link1275 link1276 link1277 link1278 link1279 link1280 link1281 link1282 link1283 link1284 link1285 link1286 link1287 link1288 link1289 link1290 link1291 link1292 link1293 link1294 link1295 link1296 link1297 link1298 link1299 link1300 link1301 link1302 link1303 link1304 link1305 link1306 link1307 link1308 link1309 link1310 link1311 link1312 link1313 link1314 link1315 link1316 link1317 link1318 link1319 link1320 link1321 link1322 link1323 link1324 link1325 link1326 link1327 link1328 link1329 link1330 link1331 link1332 link1333 link1334 link1335 link1336 link1337 link1338 link1339 link1340 link1341 link1342 link1343 link1344 link1345 link1346 link1347 link1348 link1349 link1350 link1351 link1352 link1353 link1354 link1355 link1356 link1357 link1358 link1359 link1360 link1361 link1362 link1363 link1364 link1365 link1366 link1367 link1368 link1369

[Vue.js] can't import @nota/nativescript-webview-ext/vue in nativescript vue Subscribe to RSS

i tryed to import the Nota NativeScript Webview Ext in my nativescript vue.js application (see https://market.nativescript.org/plugins/@nota%2Fnativescript-webview-ext)

i added the npm package in the playground web application without any errors or problems.

the following code is used in my app.js file:

import vue.js from ‘nativescript-vue’;
import App from ‘./components/App’;

import ‘@nota/nativescript-webview-ext/vue’;

Vue.config.silent = false;

new Vue({
render: h => h(‘frame’, [h(App)])
}).$start();

but unfortunately i got the following error

2019-06-11 15:55:30.942 nsplaydev[15435:3295521] PlayLiveSync: Uncaught Exception
2019-06-11 15:55:30.942 nsplaydev[15435:3295521] *** JavaScript call stack:
(

)
2019-06-11 15:55:30.942 nsplaydev[15435:3295521] *** Terminating app due to uncaught exception ‘NativeScript encountered a fatal error: Error: Could not find module ‘@nota/nativescript-webview-ext/vue’. Computed path ‘/var/mobile/Containers/Data/Application/F4AE564B-FAFA-4128-BC98-F087145C5FF1/Documents/Playground/LiveSync/app/tns_modules/@nota/nativescript-webview-ext/vue’.
at
1 require@file:///app/app.js:11:8
2 anonymous@file:///app/app.js:11:8
3 evaluate@[native code]
4 moduleEvaluation@[native code]
5 promiseReactionJob@[native code]
‘, reason: ‘(null)’
*** First throw call stack:
(0x1ba9623a8 0x1b9b67d00 0x10499f7f4 0x1049dda00 0x1059433c8 0x10429b3f0 0x1ba3a8fd8)
libc++abi.dylib: terminating with uncaught exception of type NSException
2019-06-11 15:55:30.942 nsplaydev[15435:3295521] PlayLiveSync: Uncaught Exception

Solution :

Not all the plugins are supported in Playground, only plugins without native dependencies are supported.

nativescript-webview-ext has native dependency for both iOS & Android, so it might not work as intended on Playground / Preview app.

FYI: Even if you use a plugin without native dependency, while running with Playground / Preview app, you should use relative path for importing anything from plugin.

[Vue.js] How to make database calls through an API in Nuxt/Vue Subscribe to RSS

I’ve been introducing myself to Vue/Nuxt and have begun experimenting with API’s. I’m trying to move the logic in my NuxtServerInit function to an API.

nuxtServerInit(vuexContext, context) {
return context.app.$axios
.$get(process.env.baseUrl + “/posts.json”)
.then(data => {
const postsArray = [];
for (const key in data) {
postsArray.push({ …data[key], id: key });
}
vuexContext.commit(“modules/modPost/setPosts”, postsArray);
})
.catch(e => context.error(e));
}

The problem I’m having is accessing the context in order to make the DB call.

The API looking something like this:

const { Router } = require(“express”);
const glob = require(“glob”);
const router = Router();

router.post(“/carousel/posts”, async function(req, res) {
return context.app.axios
.get(process.env.baseUrl + “/posts.json”)
.then(data => {
const postsArray = [];
for (const key in data) {
postsArray.push({ …data[key], id: key });
}
vuexContext.commit(“modules/modPost/setPosts”, postsArray);
})
.catch(e => context.error(e));
});

module.exports = router;

I tried making a POST request thinking I could send the context as a parameter but I it feels wrong…

async asyncData({ $axios }) {
const ps = await $axios.$post(
http://localhost:3000/api/carousel/posts", {context});
return { ps };
}

I should note here, that when fairly sure that in the API, the line is wrong:

vuexContext.commit(“modules/modPost/setPosts”, postsArray);

I believe it would generally execute in the asyncdata, on what is returned by the API.

So to summarize, there is two questions.

Is what when trying to accomplish reasonable?
What am I missing to accomplish what when trying to do?

Thanks!

Solution :

For number 2, added this to the API:

const axios = require(“axios”);
router.post(“/carousel/posts”, async function(req, res) {
return axios

I can’t believe I figured it out within ten minutes of posting. Ugh.

Still having trouble returning the result…
Also still interested in reasonability / best practices / opinions…

Solution 2:

First of all, I see here bad workflow. I suggest you to analyze how the communication between the Express and Nuxt is going. Take a look at this auth example

vuexContext.commit is the vuex method, and you use it on the server side (express), which is a mistake. In simplified terms, communication could look like:

client side request to server/call vuex action
server (express in the case) make something with data CRUD, and return response
vuex action receives a response from the server, commit changes
vue/nuxt render changes

[Vue.js] I couldn't pass data data from a function in Mounted to a method in methods through a data property (state) Subscribe to RSS

I’m pretty much new to Vue.js. I’m drawing an svg map with d3 and a geojson file. for the map to be rendered as soon as the page loads, I wrote the code in Mounted. the code also has some related functions to the map, like clicked function and hover functions to show tooltips and so on..

now here’s the scenario: when I click on a state on the map, to detect the state’s name and pass it to a method. the method then will draw a data chart based on the given state.

the “clicked” function in Mounted is handling the click event on the svg map. but I couldn’t pass the clicked state from the “Clicked” function in mounted to the method in “methods”.

this is the “clicked” function in mounted:

mounted: function mounted(){// Zoom to feature on click
function clicked(d,i) {

var width = 410;
var height = 600;
var centered;
var path = d3.geoPath()
.projection(projection);

var features = d3.select(“.features”);

var x, y, k;
if (d && centered !== d) {
// Compute the new map center and scale to zoom to
var centroid = path.centroid(d);
var b = path.bounds(d);
x = centroid[0];
y = centroid[1];
k = .8 / Math.max((b[1][0] - b[0][0]) / width, (b[1][1] - b[0][1]) / height);
centered = d
} else {
x = width / 2;
y = height / 2;
k = 1;
centered = null;
}

//Highlight the new feature
features.selectAll(“path”)
.classed(“highlighted”,function(d) {
return d === centered;
})
.style(“stroke-width”, 1 / k + “px”); // Keep the border width constant

//Zoom and re-center the map
/*features
.transition()
.duration(1000)
.attr(“transform”,”translate(“ + width / 2 + “,” + height / 2 + “)scale(“ + k + “)translate(“ + -x + “,” + -y + “)”);*/

//“state” is data property
// d.properties.gov_name_f is the clicked state to pass to
and then read it from a method
this.state= d.properties.gov_name_f;

//now here the data is passed normally inside “state” but it becomes empty when I try to read it from a method
if (this.state === “Nabeul” || this.state=== “Dar Chaabane El Fehri”) {
console.log(“samer lives here “+ this.state);
}else{
console.log(“samer doesn’t live in “+this.state);
}

};}

this is the method that to pass the “state” data property to:

methods: {
refresh(){
this.id++;
this.query = “select%20A%2CE”;
console.log(“fuck “+this.state);
//this.state is supposed to return the clicked state, but it returns an empty data property
switch (this.state) {
case “Nabeul”:
this.query = “select%20A%2CQ”;
this.id++;
console.log(this.state);
}
},
}

this is the output of the console log when I debug:
console output

the first log is from the “clicked” function in mounted and the second log in from the method that is reding the same data property but returning an empty object.

the data objects:

data() {
return {
state: “”,
gov: “gouvernorat”,
del: “delegations”,
query: “”,
gouvernorat: 0,
id: 0,
};
},

Solution :

Okay It seems like vue.js is having trouble finding the data. There’s a couple things that might cause this.

-Depending how you’re creating a vue.js object or component, the syntax for data will be different. Example:

Using export default

export default {
data() {
return {…}
},
methods:{…},
}

Or

export default {
data: ()=>{
return {…}
},
methods:{…},

}

Using vue.js object

<div id=”app”>
{ message }
</div>

<script>
var app = new Vue({
el: ‘#app’,
data: {
message: ‘Hello Vue!’
}
})
</script>

Using vue.js component

Vue.component(‘button-counter’, {
data: function () {
return {
count: 0
}
},
template: ‘<button v-on:click=”count++”>You clicked me { count } times.</button>’
})

One Other bug that may be causing is that for whatever reason in vue.js you can only call this.data in the outermost scope of a method. If you want to access it in another scope of the method, you have to use var example = this; and then in the inner scope you can use example.data. For example, here’s a sample of a project I’m working on:

export default {
data() {
return {
loading: false,
partner: ‘’,
conenctions: [],
users: [],
orgs: []
}
},
methods:{

loadConn(){
var vm = this;
axios.get(‘http://localhost:8000/ext/list\_conn/')
.then(function(response){
vm.conenctions = response.data;
console.log(vm.conenctions);
})
},
},
}

The above code will work but the following code won’t

export default {
data() {
return {
loading: false,
partner: ‘’,
conenctions: [],
users: [],
orgs: []
}
},
methods:{

loadConn(){
axios.get(‘http://localhost:8000/ext/list\_conn/')
.then(function(response){
this.conenctions = response.data;
console.log(this.conenctions);
})
},
},
}

Hopefully this helps with the bug

edit: Also make sure the data is in the outermost scope of the vue.js object or component, like in my examples. If data(){…} is inside methods:{…} or mounted{…} that could also cause the bug you’re describing

[Vue.js] How to change prop dynamically in vue-status-indicator? Subscribe to RSS

when new to VueJS and after reading this doc section and this question, I can’t figure how to change dynamically the prop active|positive|intermediary|negative and pulse of the following component (it could be another): vue-status-indicator

eg: with user.status = positive and the following wrong code :

<span v-for=”user in users” :key=”user.id”>
<status-indicator { user.status }></status-indicator>
</span>

What is the correct syntax to set theses type of props ?

Solution :

You could do something like this.. I had to write a wrapper for it to make it functional..

[CodePen Mirror]

Edit To be clear - you cannot interpolate inside an attribute.. This has to do with boolean attributes in Vue..

This:

<status-indicator active pulse />

…is the same exact thing as doing this:

<status-indicator :active=”true” :pulse=”true” />

The “wrapper” component I wrote allows you to supply a string to set the status (like you are wanting to do):

<v-indicator status=”active” pulse></v-indicator>
<!– OR –>
<v-indicator status=”positive” pulse></v-indicator>
<!– OR –>
<v-indicator status=”intermediary” pulse></v-indicator>
<!– OR –>
<v-indicator status=”negative” pulse></v-indicator>

Here is the full “wrapper” component, in .vue.js format: (added a validator for the ‘status’ prop)

<template>
<status-indicator
:active=”indicatorStatus.active”
:positive=”indicatorStatus.positive”
:intermediary=”indicatorStatus.intermediary”
:negative=”indicatorStatus.negative”
:pulse=”pulse”
\></status-indicator>
</template>

<script>
export default {
props: {
status: {
type: String,
required: true,
validator: (prop) => [
‘active’,
‘positive’,
‘intermediary’,
‘negative’,
].includes(prop)
},
pulse: {
type: Boolean,
required: false,
default: false,
},
},
data() {
return {
indicatorStatus: {
active: false,
positive: false,
intermediary: false,
negative: false,
}
}
},
watch: {
status() {
this.handleStatusChange(this.status);
}
},
methods: {
handleStatusChange(newStatus) {
Object.keys(this.indicatorStatus).forEach(v => this.indicatorStatus[v] = false);
this.indicatorStatus[newStatus] = true;
}
},
mounted() {
this.handleStatusChange(this.status);
}
}
</script>

Snippet:

const vIndicator = {
template: “#v-indicator”,
props: {
status: {
type: String,
required: true,
validator: (prop) => [
‘active’,
‘positive’,
‘intermediary’,
‘negative’,
].includes(prop)
},
pulse: {
type: Boolean,
required: false,
},
},
data() {
return {
indicatorStatus: {
active: false,
positive: false,
intermediary: false,
negative: false,
}
}
},
watch: {
status() {
this.handleStatusChange(this.status);
}
},
methods: {
handleStatusChange(newStatus) {
Object.keys(this.indicatorStatus).forEach(v => this.indicatorStatus[v] = false);
this.indicatorStatus[newStatus] = true;
}
},
mounted() {
this.handleStatusChange(this.status);
}
}

new Vue({
el: ‘#app’,
components: {
vIndicator
},
data: {
currentStatus: ‘’,
isPulse: ‘’,
},
computed: {
currentJson() {
let cj = {
currentStatus: this.currentStatus,
isPulse: this.isPulse,
};
return JSON.stringify(cj, null, 2);
}
},
mounted() {
let statuses = [“active”, “positive”, “intermediary”,”negative”];
let c = 0;
let t = 0;
this.currentStatus = statuses[c];
this.isPulse = true;
setInterval(() => {
t = c + 1 > 3 ? t + 1 : t;
c = c + 1 > 3 ? 0 : c + 1;
this.currentStatus = statuses[c];
this.isPulse = (t % 2 == 0) ? true : false;
}, 2000)
}
})
<script src=”https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<script src=”https://unpkg.com/vue-status-indicator@latest/dist/vue-status-indicator.min.js"></script>
<link href=”https://unpkg.com/vue-status-indicator@latest/styles.css" rel=”stylesheet”/>

<div id=”app”>
<p>Will alternate status as well as pulsing (pulse changes after each full loop)</p>
<!–
[status]active|positive|intermediary|negative
[pulse]true|false
-->
<v-indicator :status=”currentStatus” :pulse=”isPulse”></v-indicator>
<pre>{ currentJson }</pre>
</div>

<!– WRAPPER COMPONENT –>
<script type=”text/x-template” id=”v-indicator”>
<status-indicator
:active=”indicatorStatus.active”
:positive=”indicatorStatus.positive”
:intermediary=”indicatorStatus.intermediary”
:negative=”indicatorStatus.negative”
:pulse=”pulse”
\></status-indicator>
</script>

[Vue.js] Webpack throws error when compiling simple Vue file Subscribe to RSS

When I run webpack watch in the VS2017 task runner it throws this error:

ERROR in ./wwwroot/js/src/App.vue
Module build failed: SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (****\node_modules\vue-loader\index.js:1:80)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at loadLoader (****\node_modules\loader-runner\lib\loadLoader.js:18:17)
at iteratePitchingLoaders (****\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at runLoaders (****\node_modules\loader-runner\lib\LoaderRunner.js:365:2)
at NormalModule.doBuild (****\node_modules\webpack\lib\NormalModule.js:182:3)
at NormalModule.build (****\node_modules\webpack\lib\NormalModule.js:275:15)
at Compilation.buildModule (****\node_modules\webpack\lib\Compilation.js:157:10)
at factoryCallback (****\node_modules\webpack\lib\Compilation.js:348:12)
at ****\node_modules\webpack\lib\NormalModuleFactory.js:243:5
at ****\node_modules\webpack\lib\NormalModuleFactory.js:94:13
at ****\node_modules\tapable\lib\Tapable.js:268:11
at NormalModuleFactory.<anonymous> (****\node_modules\webpack\lib\CompatibilityPlugin.js:52:5)
at NormalModuleFactory.applyPluginsAsyncWaterfall (****\node_modules\tapable\lib\Tapable.js:272:13)
at ****\node_modules\webpack\lib\NormalModuleFactory.js:69:10
at ****\node_modules\webpack\lib\NormalModuleFactory.js:196:7
at nextTickCallbackWith0Args (node.js:452:9)
at process._tickCallback (node.js:381:13)

The App.vue.js file is a simple test file:

<template>
<div id=”app”>
<h1>XXX{ sources.length }</h1>
</div>
</template>

<script>
export default {
name: ‘app’,
data() {
return {
sources: []
}
}
}
</script>

<style>

#app {
font-family: ‘Avenir’, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}

h1, h2 {
font-weight: normal;
}

ul {
list-style-type: none;
padding: 0;
}

li {
display: inline-block;
margin: 0 10px;
}

a {
color: #42b983;
}
</style>

This works fine on another machine so I can’t understand why it’s throwing this error. I’m not that familiar with webpack/vue/typescript etc and would appreciate some help. The error message is useless.

Solution :

Updating the vue-loader module did the trick, through the task runner was still showing an error it was building correctly when webpack –watch –color was ran in powershell:

npm install vue-loader@14.2.2

https://github.com/vuejs/vue-loader/issues/1177

…the problem in Visual Studio was that Task Runner was using the webpack in node_modules/.bin folder. To rectify this, go to Tools -> Options -> Projects and Solutions -> Web Package Management and move the $(PATH) entry to the top of the list (as per Task Runner Configuration Missing in Visual Studio 2017)

[Vue.js] ASP.NET MVC - Map FormData containing array to model class Subscribe to RSS

At my front-end, when currently creating a FormData object that contains an array with the following property: “productName” and “productQuantity”. I was able to send the FormData over to my server-side. However, I could not bind any value. How do I map the list of objects in the FormData to my ASP.NET MVC Model class at my controller correctly? Below is my current code:

Update when still trying to solve this issue, help is greatly appreciated!
Update2 Just for clarity purposes, when using Vuejs as my client-side framework

Client-side

const formData = new FormData();

formData.append(“Product[0].ProductName”, “T-Shirt”);
formData.append(“Product[0].Options.Quantity”, “1”);
formData.append(“Product[1].ProductName”, “Shoe”);
formData.append(“Product[1].Options.Quantity”, “2”);

Server-side (Controller)

[HttpPost(“verifyCart”)]
public async Task<IActionResult> verifyCart([FromForm] Product[] products)
{
}

Server-side (Model)

public class Product
{
public string ProductName { get; set; }
public List<Option> Options { get; set; }
}

public class Options
{
public int Quantity { get; set; }
}

Solution :

I can make it works by changing the form data from:

formData.append(“Product[0].ProductName”, “T-Shirt”);
formData.append(“Product[0].Options.Quantity”, “1”);
formData.append(“Product[1].ProductName”, “Shoe”);
formData.append(“Product[1].Options.Quantity”, “2”);

to plural of “Product”

formData.append(“Products[0].ProductName”, “T-Shirt”);
formData.append(“Products[0].Options.Quantity”, “1”);
formData.append(“Products[1].ProductName”, “Shoe”);
formData.append(“Products[1].Options.Quantity”, “2”);

Because the parameter you are using in the post action is “products”:

[HttpPost]
public IActionResult VerifyCart([FromForm] Product[] products)
{
}

The client-side code I used to test is:

const formData = new FormData();

formData.append(“Products[0].ProductName”, “T-Shirt”);
formData.append(“Products[0].Options.Quantity”, “1”);
formData.append(“Products[1].ProductName”, “Shoe”);
formData.append(“Products[1].Options.Quantity”, “2”);

$.ajax({
type: “POST”,
url: ‘/Home/VerifyCart’,
data: formData,
processData: false,
contentType: false,
success: function (data) {
}
});

Update

I changed the client-side code to fix issue with Quantity:

const formData = new FormData();

formData.append(“Products[0].ProductName”, “T-Shirt”);
formData.append(“Products[0].Options[0].Quantity”, “1”);
formData.append(“Products[1].ProductName”, “Shoe”);
formData.append(“Products[1].Options[0].Quantity”, “2”);

$.ajax({
type: “POST”,
url: ‘/Home/VerifyCart’,
data: formData,
processData: false,
contentType: false,
success: function (data) {
}
});

[Vue.js] Add floating button inside v-img in v-card Subscribe to RSS

I would like to have a floating at the bottom right side of the image inside a card.

here’s my sample https://codepen.io/chunallen/pen/bPGJOP?editors=1000

The problem here is the button is behind of the v-card-title

Expected Result

Solution :

If you add style=”height: 100px; position: relative” to v-card-title, move the btn beneath the h3, and change bottom to top then it’ll work.

<v-card-title primary-title style=”height: 100px; position: relative”>
<div>
<h3 class=”headline mb-0”>Kangaroo Valley Safari</h3>
<v-btn color=”pink” dark small absolute top right fab>
<v-icon>add</v-icon>
</v-btn>
</div>
</v-card-title>

Sample

[Vue.js] html dialog element is covering up invisible recaptcha challenge popup. how to fix this? Subscribe to RSS

https://codepen.io/adamchenwei/pen/agbPYJ
access the example in incognito mode, click “open” button to open the sample signin form, then click “Sign Up” button to trigger the challenge.
when not sure if its a not fixable problem with using recaptcha inside dialog or its more of a fixable thing with some sort of hack of css and html? Tried z-index on the dialog, that did not work at all..

HTML

<div id=”app”>
<div class=”container my-4”>
<div class=”row justify-content-center”>
<div class=”col-md-8”>
<h2 class=”text-center mb-4”>
Sign Up Form with Google reCAPTCHA
</h2>
<dialog ref=”mydialog”>
<form
method=”post”>
<div class=”form-group”>
<input
type=”email”
name=”email”
class=”form-control”
placeholder=”Enter the e-mail address”
required />
</div>
<div class=”form-group”>
<input
type=”password”
name=”password”
class=”form-control”
placeholder=”Enter the password”
required />
</div>
<div class=”form-group”>
<vue-recaptcha
ref=”recaptcha”
size=”invisible”
:sitekey=”sitekey”
@verify=”register”
@expired=”onCaptchaExpired”
/>
<button
type=”submit”
class=”btn btn-primary btn-block”
@click=”validate”>
Sign Up
</button>
</div>
</form>
</dialog>
<button @click=”openDialog”>open</button>
</div>
</div>
</div>
</div>

JS

new Vue({
el: ‘#app’,

components: { VueRecaptcha },

data () {
return {
email: null,
password: null,
recaptchaToken: null,
sitekey: ‘6Lfe33gUAAAAAMCuDwRfhSUV4sGkqGDaGrKqjkmZ’
}
},

methods: {
openDialog() {
this.$refs.mydialog.showModal();
},
register () {
// make post request to the server
},

validate () {
// if validate true exec recaptcha
this.$refs.recaptcha.execute()
},

onCaptchaExpired () {
this.$refs.recaptcha.reset()
}
}
});

Solution :

So heres the thing:

If you use <dialog></dialog> it is hidden by default.

Either use <dialog open></dialog>to show the dialog on startup,
or open the dialog via some js:

// Update button opens a modal dialog
updateButton.addEventListener(‘click’, function() {
dialog.showModal();
});

HOWEVER. the dialog element is not very widly supported, so I would
really advise you NOT to use it.

https://caniuse.com/#feat=dialog

You should therefor change

<dialog class=”my-dialog”></dialog>

to

<div class=”my-dialog”></div>

You should then see it in in all Browsers, and this is the supported way of doing it.

[Vue.js] How do you use selectors in Vue? Subscribe to RSS

there is a couple of select elements on my page and want to get a list of the values of all the selected on the page with a certain class

<select class=”selectedCam” @change=”dosomething” >
<option value=”” disabled selected>select from below</option>
<option value=”1”>Direction 1</option>
<option value=”2”>Direction 2</option>
….
</select >

If a value is chosen from one select in my element to disable it in all the other selects in my element that share the same class. This list will be dynamic based on how many cams are plugged into my system at the time so I won’t know how many are generated at any point in time.

I know I should not manipulate the Dom with JQuery when using vuejs.

But I know with JQuery I could look for $(‘. selectedCam’) and get an array of objects that shared this class and find the current values for these elements that I could use on my onChange event to disable these options in the other selects once chosen.

Is there something similar in vue.js Js?
Or should I try a different approach in vue.js Js to disable these options in the other selects that get generated on the page?

Solution :

To disable a selected value from a select tag in Vue, my approach would be this:

template

<select class=”selectedCam” @change=”dosomething” v-model=’selectedCam1’>
<option value=”” disabled selected>select from below</option>
<option value=”1” :disabled=”selectedCam2 == ‘Direction 1’ || selectedCam3 == ‘Direction 1’”>Direction 1</option>
<option value=”2”>Direction 2</option>
….
</select >
<select class=”selectedCam” @change=”dosomething” v-model=’selectedCam2’>
<option value=”” disabled selected>select from below</option>
<option value=”1”>Direction 1</option>
<option value=”2”>Direction 2</option>
….
</select >
<select class=”selectedCam” @change=”dosomething” v-model=’selectedCam3’>
<option value=”” disabled selected>select from below</option>
<option value=”1”>Direction 1</option>
<option value=”2”>Direction 2</option>
….
</select >

data

data () {
return {
selectedCam1: ‘’,
selectedCam2: ‘’,
selectedCam3: ‘’,

}
}

So, here you can see I set option 1 from the first select to disable if select 2 or 3 is already set to Direction 1.

Solution 2:

Disable selected values with v-if. See working example on codepen

Example

<div id=”vue”>
<div class=”input-select”>
<label>Country</label>
<select v-model=”selected” @change=”selected.active = false”>
<option v-for=”country in countries” v-bind:value=”country” :key=”country.name” v-if=”country.active”>
{ country.name }
</option>
</select>

<label>Country2</label>
<select v-model=”selected” @change=”selected.active = false”>
<option v-for=”country in countries” v-bind:value=”country” :key=”country.name” v-if=”country.active”>
{ country.name }
</option>
</select>
</div>

<h2>Selected: <strong>{ selected } ({ selectedName })</strong></h2>
</div>

Updated

<div id=”vue”>
<div class=”input-select”>
<label>Country</label>
<select v-model=”selected” @change=”setHidden()”>
<option v-for=”country in countries” v-bind:value=”country” :key=”country.name” :disabled=”!country.active”>
{ country.name }
</option>
</select>

<label>Country2</label>
<select v-model=”selected2”>
<option v-for=”country in countries” v-bind:value=”country” :key=”country.name” v-if=”country.active”>
{ country.name }
</option>
</select>
</div>

<h2>Selected: <strong>{ selected.name }</strong>
<h2>Selected2: <strong>{ selected2.name }</strong>
</h2>
</div>