Vue.js Digest 🇷🇺 🇺🇸
39 subscribers
389 photos
745 links
Дайджест новостей из мира vuejs
Download Telegram
Filtering Data Di Vue

https://dev.to/medan_in_code/filtering-data-di-vue-e94
Tutorial kali ini akan membahas bagimana jika kita ingin memfilter data dengan vue.Karena disini kita akan menggunakan directive v-for dan v-if ada baiknya teman-teman membaca dahulu disini.

Percabangan Di Vue Js


Perulangan Di Vue Js
Misalnya kita punya data seperti dibawah ini.



products:[
{
name:"dress zara",
gender:"wanita",
size:"S"
},
{
name:"baju offwhite",
gender:"pria",
size:"L"
}
]


Kita akan mencoba memfilter data yang akan tampil berdasarkan jenis kelamin.Disini kita akan menggunakan beberapa cara.

v-if
computed
methods




Menggunakan v-if

Untuk penggunaan dengan v-if kurang lebih seperti kode dibawah ini.



<h1>Pakaian pria</h1>
<ul>
<li v-for="product in products" v-if="product.gender==='pria'">
{{ product.name }}
</li>
</ul>
<h1>Pakaian wanita</h1>
<ul>
<li v-for="product in products" v-if="product.gender==='wanita'">
{{ product.name }}
</li>
</ul>


Bisa dilihat pada code diatas kita cukup menambahkan v-if dengan kondisi jika object dengan key gender sesuai dengan jenis kelamin yang kita tentukan.
Maka akan didapatkan hasil seperti dibawah ini.




Menggunakan properti computed

Untuk penggunaan dengan properti computed bisa dilihat pada kode dibawah.



data: () => {
return {
products: [
{
name: "dress zara",
gender: "wanita",
size: "S"
},
{
name: "baju offwhite",
gender: "pria",
size: "L"
}
]
};
},
computed:{
produkPria:function(){
return this.products.filter(function (data) {
return data.gender === 'pria'
})
},
produkWanita:function(){
return this.products.filter(function (data) {
return data.gender === 'wanita'
})
}
}


Jika dilihat di kode diatas kita membuat dua buah fungsi masing-masing untuk memfilter data berdasarkan jenis kelamin.
Untuk htmlnya sendiri bisa dilihat dibawah,kita langsung membuat v-for berdasarkan fungsi yang terdapat pada properti computed.



<h1>Pakaian pria</h1>
<ul>
<li v-for="product in produkPria">
{{ product.name }}
</li>
</ul>
<h1>Pakaian wanita</h1>
<ul>
<li v-for="product in produkWanita">
{{ product.name }}
</li>
</ul>





Menggunakan properti methods

Dengan properti methods kita bisa membuat untuk kasus diatas menjadi 1 fungsi saja.Berbeda dengan computed karena computed memiliki parameter.



data: () => {
return {
products: [
{
name: "dress zara",
gender: "wanita",
size: "S"
},
{
name: "baju offwhite",
gender: "pria",
size: "L"
}
]
};
},
methods: {
pakaian: function(gender) {
return this.products.filter(function(data) {
return data.gender === gender;
});
}
}


Pada kode diatas isi fungsi kurang lebih sama seperti yang kita gunakan pada parameter hanya berbeda di parameter.Untuk datanya kita berikan sesuai dengan parameter.
Untuk htmlnya seperti dibawah ini.



<h1>Pakaian pria</h1>
<ul>
<li v-for="product in pakaian('pria')">{{ product.name }}</li>
</ul>
<h1>Pakaian wanita</h1>
<ul>
<li v-for="product in pakaian('wanita')">{{ product.name }}</li>
</ul>


Kita cukup memanggil methods tersebut di v-for dengan parameter gender.
Sekian dulu pembahasan mengenai filtering data,jika ada yang kurang dipahami,silahkan tanyakan dibawah.
How To Install Vue 3 in Laravel 8 From Scratch

https://medium.com/techvblogs/how-to-install-vue-3-in-laravel-8-from-scratch-908b78b63ce?source=rss------vuejs-5
Nov 19, 2021, Originally published at techvblogs.com ・4 min readContinue reading on TechvBlogs »
VueJS — Neden Composition API

https://ali-menekse.medium.com/vuejs-neden-composition-api-76f2dbb83434?source=rss------vuejs-5
Vue projelerinde kod büyükdükçe fonksiyonları yeniden kullanmak ve bunların okunabilirliğini sağlamak için daha fazla dikkat ve code…Continue reading on Medium »
Why Composition API in VueJS?

https://ali-menekse.medium.com/why-composition-api-in-vuejs-b0fc39bbf7ce?source=rss------vuejs-5
We need time to code review, refactoring, and readable/clear code when your application scale increases. We use Mixins for reusable…Continue reading on Medium »
How to seperate DEV and PROD Firebase Projects in NUXT 🔥

https://dev.to/peterf2170/how-to-seperate-dev-and-prod-firebase-projects-in-nuxt-368k
Just as easy as deploying a NUXT SSR App using Vercel is the implementation of DEV and PROD environments for 2 different firebase Projects.
First TODO is to create seperate projects in Firebase. I named mine project-dev and project-prod.
In your nuxt.config.js, all you have to add is the following env attribute:



export default {
env: {
NODE_ENV: process.env.NODE_ENV
},


In your firebase.js or .ts file, you have to create 2 seperate config variables for the 2 firebase projects.



const configDev = {
apiKey: 'verysecret',
authDomain: 'project-dev.firebaseapp.com',
projectId: 'project-dev',
storageBucket: 'project-dev.appspot.com',
messagingSenderId: 'verysecret',
appId: 'verysecret',
measurementId: 'verysecret'
};
const configProd = {
apiKey: 'verysecret',
authDomain: 'project-prod.firebaseapp.com',
projectId: 'project-prod',
storageBucket: 'project-prod.appspot.com',
messagingSenderId: 'verysecret',
appId: 'verysecret'
};
let firebaseApp;
if (!getApps().length) {
if (process.env.NODE_ENV === 'development') {
firebaseApp = initializeApp(configDev);
} else {
firebaseApp = initializeApp(configProd);
}
}


Thats it. As easy as it could be. Developing on localhost will now use the dev Firebase project, deploying it (for example on vercel) will automatically change the project to project-prod.
If you just added a new Firebase PROD Project, you will have to activate your features (Firestore, Auth, ...), then it should work just as the DEV project.
Creating Data Tables with Vuetify

https://javascript.plainenglish.io/creating-data-tables-with-vuetify-fc5d3d810f11?source=rss------vuejs-5
Learn to create data tables with VuetifyContinue reading on JavaScript in Plain English »
Django-Vue.js ile SSE(Server-sent events) Kullanımı

https://burakgocer.medium.com/django-vue-js-ile-sse-server-sent-events-kullan%C4%B1m%C4%B1-f2eae0b2d874?source=rss------vuejs-5
Bu yazıda Django ve Vue.js teknolojileri kullanılarak temel düzeyde server ile client arasında anlık veri aktarımı için kullanılan SSE…Continue reading on Medium »
Why I prefer the Vue.js framework

https://medium.com/@mazraara/why-i-prefer-the-vue-js-framework-9fd88615087b?source=rss------vuejs-5
A few years ago, we decided to use Vue.js as the standard framework for all front-end development of web applications. There are many…Continue reading on Medium »
ELI5: Reactivity in Vue 3

https://dev.to/morgenstern2573/eli5-reactivity-in-vue-3-4o40
Reactivity. It's a popular buzzword. It's also one of the most convenient features of front-end frameworks.

What is it exactly, and how does it work in Vue 3?



Prerequisite Knowledge


Basic JavaScript and JS objects
Basic knowledge of Vue.js




What is reactivity?


Reactivity is a programming paradigm that allows us to adjust to changes in a declarative manner.

Vue 3.x documentation
We say a value is reactive when it can update itself in response to changes in values it depends on. What do we mean by depends on? Let's take an example.



let val1 = 2
let val2 = 3
let sum = val1 + val2


The value of sum is always determined by the values of val1 and val2, so we say that sum depends on val1 and val2.
What happens to sum when one of the values it depends on changes? In regular JavaScript, it stays the same.



console.log(sum) // 5
val1 = 3
console.log(sum) // Still 5


But if sum was reactive,



console.log(sum) // 5
val1 = 3
console.log(sum) // Sum is 6!


The value of sum would change in response to the change in a value it depended on.



What does Vue need to make a value reactive?

Vue needs to know:

what dependencies that value has.
when those dependencies change.

Vue also needs to be able to re-calculate values when their dependencies change.



How Vue knows when dependencies change

Vue wraps the data object of all components with an ES6 Proxy.

A proxy is an object that wraps a target object.
This is important because all reactive values depend (directly or not) on the properties in a component's data object.
Proxies allow you to intercept all requests to get or set properties of the target. They also let you run any code in response to those requests.
Thanks to this, when code attempts to change one of the properties of a data object, Vue intercepts it and is aware of it.
Vue can then re-calculate any functions that depend on that value. But how does Vue know which functions depend on which values?



How Vue knows which dependencies belong to a value

To make our value reactive, we need to wrap it in a function. Using sum to illustrate again:



// we need to go from
let val1 = 2
let val2 = 3
let sum = val1 + val2
// to
const updateSum = () => {
sum = val1 + val2
}


Vue then wraps all such functions with an effect. An effect is a function that takes another function as an argument. Vue then calls the effect in place of that function.
When Vue calls an effect, the effect:

Records that it's running.
Calls the function it received as an argument.
Removes itself from the list of running effects after the function ends.

Remember all source values come from a Proxy (the data component)? While executing the function it wraps, the effect will need a property from the data object, and try to read it.
The Proxy will intercept that read request. Vue checks which effect is currently running. It then records that the effect depends on the property it tried to read. This is how Vue knows which values depend on which properties.



So how does Vue know when to re-run the functions that return dependent values?

The answer is once again the magic of Proxies. Proxies can intercept requests to set property values too.
Remember we now have a record of effects, as well as the values they depend on. When the value of a property in data changes, Vue needs to do one thing: check that record and update the source value.
Vue can then re-run all the effects that depend on it, and thus update the values.



Conclusion

This article is a simplified overview of how reactivity works in Vue 3. If you'd like to read more on the subject, here are some resources:

Understanding the New Reactivity System in Vue 3
Reactivity in Depth
Configurando Teste Unitário no VueJS + Jest

https://dev.to/franciscobressa/configurando-teste-unitario-no-vuejs-jest-3dk6
1. Adicione Jest ao seu projeto

Rode o seguinte comando dentro do diretório de seu projeto



vue add unit-jest


2. Scripts

Para rodar os testes adicione os seguintes comandos nos Scripts de seu package.json



"test:unit": "vue-cli-service test:unit",
"test:watchAll": "jest --verbose --watchAll",


3. Configure as Extensões que seus módulos usarão

Adicione em seu package.json



"jest": {
"moduleFileExtensions": [
"js",
"vue"
],
}


4. Mapear os caminhos

Adicione os mapeamentos que precisar na opção moduleNameMapper em seu jest.config.js



module.exports = {
preset: '@vue/cli-plugin-unit-jest',
moduleNameMapper: {
"@themeConfig(.*)": "<rootDir>/themeConfig.js",
"@core/(.*)": "<rootDir>/src/@core/$1",
"^@/(.*)$": "<rootDir>/src/$1"
}
}


5. Ignorar arquivos

Em seu jest.config.js a opção transformIgnorePatterns ignorará todo tipo de arquivo que coincidir com o padrão regexp. Como por exemplo:



module.exports = {
preset: '@vue/cli-plugin-unit-jest',``
transformIgnorePatterns: ['/node_modules/(?!vee-validate/dist/rules)'],
}
Creating A Map With Markers In VueJs

https://nikakharebava.medium.com/creating-a-map-with-markers-in-vuejs-22d9eb44c556?source=rss------vuejs-5
In this article, we will take a look at how we can create a map component in VueJs using a free plugin.Continue reading on Medium »
Implement different types of sliders using Vue 3 and Swiper 7

https://blog.canopas.com/ifferent-types-of-sliders-using-vue-3-and-swiper-7-f6dc10a3eeed?source=rss------vuejs-5
Using swiper.js, we can integrate eye-catching sliders in different javascript frameworks like Vue, angular, react, etc. It includes many…Continue reading on Canopas Software »
Vue 3 + Vite + Quasar issue

https://dev.to/ingsm/vue-3-vite-quasar-issue-2945
Namaste to everybody!;)
I would like to share with you one issue that i had today with my set-up of Vue, Vite and Quasar. The issue is small and it won't get much of your time and I hope it would be useful for somebody
I had troubles with default Quasar prebuild icons. Built a dev server I received an error:

The request url "D:/projects/Webware/Current/vite-vue-quasar/node_modules/@quasar/extras/roboto-font/web-font/KFOmCnqEu92Fr1Mu4mxM.woff" is outside of Vite serving allow list.

I had the following vite.config.js structure:



import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { quasar, transformAssetUrls } from '@quasar/vite-plugin'
// https://vitejs.dev/config/
export default defineConfig({
server: {
fs: {
// Allow serving files from one level up to the project root
}
},
plugins: [vue({
template: { transformAssetUrls }
}),
quasar({
sassVariables: '@/assets/styles/quasar-variables.sass'
})
],
resolve: {
alias: {
'@/': `${path.resolve(__dirname, 'src')}/`
}
}
})


The tip here is that that from Vite v2.7 server strict mode is set to true by default and it restricts serving files outside of workspace root.
Link to official docs: https://vitejs.dev/config/#server-fs-strict
Below you can find an option to solve this problem with enabled strict mode, but I just turn the strict mode off.



export default defineConfig({
server: {
fs: {
// Allow serving files from one level up to the project root
strict: false,
}
},


Thank you for reading and I'm eager to hear if my decision is not right enough;)
Vue.js Interview Challenge — #13 — Conditional Login Form

https://medium.com/js-dojo/vue-js-interview-challenge-13-conditional-login-form-8d9e3d7ab338?source=rss------vuejs-5
Problem statementContinue reading on Vue.js Developers »
Vue.js Interview Challenge — #13— Conditional Login Form — Solution

https://medium.com/@m.rybczonek/vue-js-interview-challenge-13-conditional-login-form-solution-280d34994f5f?source=rss------vuejs-5
SolutionContinue reading on Medium »
Getting Child Component Input Data to Parent, gathering into Array in Vue.js?

https://ewumesh.medium.com/getting-child-component-input-data-to-parent-gathering-into-array-in-vue-js-bcce136ecef7?source=rss------vuejs-5
For example, here, when I click the button, I will have one more component, it means it will have new data, so I want to gather all info…Continue reading on Medium »
4 Trending Vue.js Projects in 2022

https://javascript.plainenglish.io/4-trending-vue-js-projects-in-2022-77b308810c29?source=rss------vuejs-5
Trending projects of January for Vue.jsContinue reading on JavaScript in Plain English »
Electron.js ve Vue.js: İki Süper Güç İle Masaüstü Uygulaması

https://medium.com/berkut-teknoloji/electron-js-ve-vue-js-i%CC%87ki-s%C3%BCper-g%C3%BC%C3%A7-i%CC%87le-masa%C3%BCst%C3%BC-uygulamas%C4%B1-dcb7f17020a3?source=rss------vuejs-5
Electron.js Nedir?Continue reading on Berkut Teknoloji »
How to Use Color in Vuetify

https://codingbeauty.medium.com/how-to-use-color-in-vuetify-f48cb9153829?source=rss------vuejs-5
Learn how to use color in VuetifyContinue reading on Medium »