Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Hello Vue</title>
- <meta charset="utf-8">
- <!-- https://unpkg.com/vue@2.6.11/dist/vue.min.js -->
- <!-- подключение фреймворка vue.js -->
- <script type="text/javascript" src="https://unpkg.com/vue"></script>
- <style type="text/css">
- body {
- background: #20262E;
- padding: 20px;
- font-family: Helvetica;
- }
- #app {
- background: #fff;
- border-radius: 4px;
- padding: 20px;
- transition: all 0.2s;
- }
- li {
- margin: 8px 0;
- }
- h2 {
- font-weight: bold;
- margin-bottom: 15px;
- }
- del {
- color: rgba(0, 0, 0, 0.3);
- }
- </style>
- </head>
- <body>
- <!-- элемент div c идентификатором app -->
- <!-- v-for -->
- <div id="app">
- <h2>Todos:</h2>
- Название задачи <input type="text" v-model="newTaskText" >
- Статус <input type="checkbox" v-model="newTaskState" >
- <input type="button" value="ADD" @click="addTask()">
- <ol>
- <li v-for="todo in todos">
- <label>
- <input type="checkbox" @change="toggle(todo)" :checked="todo.done">
- <del v-if="todo.done">
- {{ todo.text }}
- </del>
- <span v-else>
- {{ todo.text }}
- </span>
- </label>
- </li>
- </ol>
- </div>
- </body>
- <script type="text/javascript">
- // создаем объект Vue (экземпляр Vue)
- new Vue({
- el: "#app",
- data: {
- newTaskText: "",
- newTaskState: false,
- todos: [
- { text: "Learn JavaScript", done: false },
- { text: "Learn Vue", done: false },
- { text: "Play around in JSFiddle", done: true },
- { text: "Build something awesome", done: true }
- ]
- },
- methods: {
- toggle: function(todo){
- todo.done = !todo.done
- },
- addTask(){
- if(this.newTaskText!='') {
- this.todos.push({"text": this.newTaskText, "done": this.newTaskState });
- this.newTaskText='';
- this.newTaskState=false;
- }
- }
- }
- })
- </script>
- </html>
Add Comment
Please, Sign In to add comment