新运行了一个todolist的vue文件,从官网衍生出的

news/2024/7/10 2:49:55 标签: vue

https://codesandbox.io/s/vue-todo-list-app-with-single-file-component-vzkl3?file=/src/App.vue:0-1551

下载代码
npm install
npm run dev
即可
两个代码
app.vue

<template>
  <div class="wrapper">
    <h1>My Todo List</h1>
    <form @submit.prevent="addTodo">
      <input type="text" name="todo-text" v-model="newTodoText" placeholder="New todo">
    </form>
    <ul v-if="todos.length">
      <TodoItem v-for="todo in todos" :key="todo.id" :todo="todo" @remove="removeTodo"/>
    </ul>
    <p class="none" v-else>Nothing left in the list. Add a new todo in the input above.</p>
  </div>
</template>

<script>
import TodoItem from "./TodoItem.vue"

let nextTodoId = 1

const createTodo = text => ({
  text,
  id: nextTodoId++
})

export default {
  components: {
    TodoItem
  },

  data() {
    return {
      todos: [
        createTodo("Learn Vue"),
        createTodo("Learn about single-file components"),
        createTodo("Fall in love ❤️")
      ],

      newTodoText: ""
    }
  },

  methods: {
    addTodo() {
      const trimmedText = this.newTodoText.trim()

      if (trimmedText) {
        this.todos.push(createTodo(trimmedText))
      }

      this.newTodoText = ""
    },

    removeTodo(item) {
      this.todos = this.todos.filter(todo => todo !== item)
    }
  }
}
</script>

<style lang="stylus">
*, *::before, *::after 
  box-sizing border-box

html, body
  font 16px/1.2 BlinkMacSystemFont, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif
  padding 10px

.wrapper
  width 75%
  margin 0 auto

form
  margin-bottom 20px

input[type="text"]
  width 100%
  padding 10px
  border 1px solid #777

ul, li
  margin 0
  padding 0

p.none
  color #888
  font-size small
</style>

TodoItem.vue

<template>
  <li>
    <span>{{ todo.text }}</span>
    <button @click.prevent="$emit('remove', todo)">Remove</button>
  </li>
</template>

<script>
export default {
  props: {
    todo: {
      required: true,
      type: Object
    }
  }
}
</script>


<style lang="stylus" scoped>
li
  display flex
  margin 5px 0

  span
    flex 1
  
  button
    border 1px solid orange
    background orange 
    color white
    font-size 0.8rem
    padding 2px 4px
    cursor pointer

    &:hover
      border-color #ff8100
      background #ff8100
</style>

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Vue Simple Todo App with SFC</title>
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
    />
    <link rel="stylesheet" href="/dist/main.css" />
  	<link id="external-css" rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" media="all">
</head>
  <body>
    <div id="app"></div>
    <script src="/dist/main.js"></script>
  </body>
</html>

main.js
不变


http://www.niftyadmin.cn/n/957842.html

相关文章

python报“IndentationError: unexpected indent“的解决方法.

python是一种对缩进非常敏感的语言&#xff0c;最常见的情况是tab和空格的混用会导致错误&#xff0c;或者缩进不对&#xff0c;而这是用肉眼无法分别的。 将def 前面的空格去掉&#xff0c;然后对print做下tab空格,问题就解决了&#xff0c;如下图: Python语言是一款对缩进非…

tensorflow框架学习(一)placeholder 与variable

1. placeholder —占位符 参考 http://www.tensorfly.cn/tfdoc/api_docs/python/io_ops.html placeholder, 译为占位符&#xff0c;官方说法:”TensorFlow provides a placeholder operation that must be fed with data on execution.” 即必须在执行时feed值。 placeholde…

单页面html的代码和vite npm的代码试一试成不成功

43html 成功 <!DOCTYPLE html> <html><head><title>222222</title></head><body><script src"https://unpkg.com/vuenext"></script><div id"bind-attribute"><span v-bind:title"m…

《TensorFlow 实战Google深度学习框架》中MNIST数字识别问题程序的重构

前馈神经网络计算部分 #mnist_inference.py import tensorflow as tfINPUT_NODE 784 # 输入节点数 OUTPUT_NODE 10 # 输出节点数 LAYER1_NODE 500 # 隐层节点数def get_weight_variable(shape, regularizer):weights tf.get_variable("weights", shape,initi…

windows 服务自动启动脚本 监控windows服务,并且自动启动

echo off rem 定义循环间隔时间和监测的服务&#xff1a; set secs3600 set srvname"myService" echo. echo echo 查询计算机服务的状态&#xff0c; echo 每间隔%secs%秒种进行一次查询&#xff0c; echo 如发现其停止&#x…

mounted和methods用法示例

<!DOCTYPE html> <html> <head> <meta charset"utf-8"> <title>Vue的方法_侠课岛(9xkd.com)</title> <script src"https://cdn.jsdelivr.net/npm/vue2.5.16/dist/vue.js"></script> </head> <bo…

tensorflow 中 variable_scope 与name_scope函数解析

前言 还是那句老话&#xff0c;学习tensorflow最好的方法就是阅读他的官方API手册。 知乎上面一个有意思的问答&#xff1a;tensorflow里面name_scope, variable_scope等如何理解&#xff1f; 先引用知乎上答主的话&#xff1a; 主要是因为 变量共享 的需求。而这就不得不谈…

SpringMVC异步处理(Callable和DeferredResult)

官方文档中说DeferredResult和Callable都是为了异步生成返回值提供基本的支持。简单来说就是一个请求进来&#xff0c;如果你使用了DeferredResult或者Callable&#xff0c;在没有得到返回数据之前&#xff0c;DispatcherServlet和所有Filter就会退出Servlet容器线程&#xff0…