Vue Js
Vue Js
Date: 04/02/24
Roll No. and Name: 22BCE305 ROSHNI PANKAJKUMAR RANA
Course Code and Name: 2CS201 FULL STACK WEB DEVELOPMENT
Practical-7:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script
src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
<div id="app" class="center-container">
</div>
<script src="app.js"></script>
</body>
</html>
II. Creating a Dynamic List with Vue.js.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script
src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<style>
body {
padding: 0;
background-color: #f8dada;
#app {
max-width: 600px;
padding: 20px;
background-color: #db6363;
border-radius: 8px;
h2 {
text-align: center;
color: #333;
ul {
list-style-type: none;
padding: 0;
li {
margin-bottom: 8px;
padding: 10px;
background-color: #f0f0f0;
border-radius: 4px;
input[type="text"] {
padding: 8px;
font-size: 16px;
border-radius: 4px;
margin-right: 8px;
button {
padding: 8px 16px;
font-size: 16px;
background-color: #a12836;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
button:hover {
background-color: #741c27;
</style>
</head>
<body>
<div id="app">
<ul v-list="items"></ul>
<div>
<input type="text" v-model="newItem" placeholder="Add
new item">
</div>
</div>
<script>
Vue.directive('list', {
bind(el, binding) {
const ul = document.createElement('ul');
binding.value.forEach(item => {
const li = document.createElement('li');
li.textContent = item;
ul.appendChild(li);
});
el.appendChild(ul);
},
update(el, binding) {
const ul = el.querySelector('ul');
ul.innerHTML = '';
binding.value.forEach(item => {
const li = document.createElement('li');
li.textContent = item;
ul.appendChild(li);
});
});
new Vue({
el: '#app',
data: {
},
methods: {
addItem() {
this.items.push(this.newItem.trim());
}
}
});
</script>
</body>
</html>
III. Custom Directive Create a directive that formats and displays dates in a
human readable format.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Custom Directive for Date Formatting</title>
<style>
/* Apply modern styles to the body */
body {
font-family: 'Times New Roman', sans-serif;
background: linear-gradient(to top, #aaefd2,#ffffff,
#aaefd2); /* Gradient background */
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}