• vue脚手架基础demo1


    vue脚手架基础demo1


    目录

    vue脚手架基础demo1

    bootstrap CSS样式引入

    增删查demo

    bootstrap常用样式

    template原型

    demo1【template的声明以及使用】

    demo2(自定义组件名称)

    demo3(自定义组件传参)

    demo4(子父组件传参) 

    demo4(slot插槽使用)


    bootstrap CSS样式引入

    npm i jquery bootstrap@4.6 popper.js -S

    在main.js中引入

    1. import 'bootstrap/dist/js/bootstrap.js'
    2. import 'bootstrap/dist/css/bootstrap.css'

    在根目录创建【vue.config.js】文件

    1. const webpack = require("webpack")
    2. module.exports = {
    3. // 配置插件参数
    4. configureWebpack: {
    5. plugins: [
    6. // 配置 jQuery 插件的参数
    7. new webpack.ProvidePlugin({
    8. // 引入jquery
    9. $: 'jquery',
    10. jQuery: 'jquery',
    11. 'window.jQuery': 'jquery',
    12. // 引入popper.js
    13. Popper: ['popper.js', 'default']
    14. })
    15. ]
    16. }
    17. }

    增删查demo

    包含技术点:

     源码

    1. <template>
    2. <div id="show">
    3. <p>
    4. 编号:<input type="text" v-model="id" class="form-control" placeholder="请输入id" /> 诗名:
    5. <input type="text" v-model="name" class="form-control" placeholder="请输入诗名" /> 作者:
    6. <input type="text" v-model="worker" class="form-control" placeholder="请输入作者" /><br/> 经典词:
    7. <input type="text" v-model="famous" class="form-control" placeholder="请输入经典词" />
    8. <button v-on:click="addInfo" class="btn btn-primary">提交button>
    9. p>
    10. <hr/>
    11. <p><input type="text" v-model="SelectKey" placeholder="请输入搜索内容" />p>
    12. <hr/>
    13. <table class="table table-hover table-bordered" style="text-align: center">
    14. <tr class="info">
    15. <td>编号td>
    16. <td>诗名td>
    17. <td>作者td>
    18. <td>名句td>
    19. <td>操作td>
    20. tr>
    21. <tr v-for="(item,index) in newlist" :key="item">
    22. <td>{{item.id}}td>
    23. <td>{{item.name}}td>
    24. <td>{{item.worker}}td>
    25. <td><pre>{{item.famous}}pre>td>
    26. <td><button v-on:click="del(index)" class="btn btn-primary">删除button>td>
    27. tr>
    28. table>
    29. div>
    30. template>
    31. <script>
    32. export default {
    33. name:"demo1",
    34. data:function(){
    35. return {
    36. list: [{
    37. id: 1,
    38. name: "将进酒",
    39. worker: "李白",
    40. famous: "烹羊宰牛且为乐,会须一饮三百杯!"
    41. }, {
    42. id: 2,
    43. name: "长恨歌",
    44. worker: "白居易",
    45. famous: "回眸一笑百媚生,六宫粉黛无颜色。"
    46. }, {
    47. id: 3,
    48. name: "永遇乐",
    49. worker: "辛弃疾",
    50. famous: "想当年,金戈铁马,气吞万里如虎。"
    51. }, ],
    52. SelectKey: "",
    53. id: 0,
    54. name: "",
    55. worker: "",
    56. famous: ""
    57. }
    58. },
    59. computed: {
    60. newlist: function() {
    61. //复制一个this的分身
    62. var _this = this;
    63. return _this.list.filter(function(item) {
    64. console.log(item);
    65. return item.famous.indexOf(_this.SelectKey) != -1;
    66. });
    67. }
    68. },
    69. methods: {
    70. addInfo: function() {
    71. this.list.push({
    72. id: this.id,
    73. name: this.name,
    74. worker: this.worker,
    75. famous: this.famous
    76. });
    77. },
    78. del: function(index) {
    79. if (confirm("是否删除此条信息?")) {
    80. this.list.splice(index, 1);
    81. }
    82. }
    83. }
    84. }
    85. script>

    bootstrap常用样式

    常用样式:

    table

    【table-striped】【table-bordered】【table-hover】【table-condensed】

    form

    【form-control】【btn-primary】【btn-warning】【btn-danger】【disabled】【btn-block】

    ul

    【nav nav-pills水平ul】【nav-stacked垂直ul】【active选中】【badge徽章】

    pre

    【pre-scrollable滚动条】

    template原型

    demo1【template的声明以及使用】

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>Documenttitle>
    8. <style>
    9. * {
    10. margin: 0px;
    11. padding: 0px;
    12. }
    13. body {
    14. overflow: hidden;
    15. }
    16. .myh {
    17. background-color: #2E6EC2;
    18. color: white;
    19. font-size: 3rem;
    20. height: 10vh;
    21. }
    22. .myc {
    23. background-color: #F8F1DC;
    24. font-size: 5rem;
    25. height: 85vh;
    26. text-align: center;
    27. line-height: 85vh;
    28. }
    29. .myf {
    30. background-color: #2E6EC2;
    31. font-size: 2rem;
    32. height: 5vh;
    33. }
    34. style>
    35. head>
    36. <body>
    37. <div id="app">
    38. <myheader>myheader>
    39. <mycontent>mycontent>
    40. <myfooter>myfooter>
    41. div>
    42. <script src="js/vue.js">script>
    43. <script>
    44. //创建模板
    45. var myh = Vue.extend({
    46. template: "
      后台管理系统
      "
    47. });
    48. var myc = Vue.extend({
    49. template: "
      后台管理中心内容
      "
    50. });
    51. var myf = Vue.extend({
    52. template: "
      版权所有:项目开发组
      "
    53. });
    54. //绑定组件
    55. Vue.component("myheader", myh);
    56. Vue.component("mycontent", myc);
    57. Vue.component("myfooter", myf);
    58. //加载vue
    59. new Vue({
    60. el: "#app"
    61. })
    62. script>
    63. body>
    64. html>

    demo2(自定义组件名称)

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>Documenttitle>
    8. head>
    9. <body>
    10. <div id="app">
    11. <h1>软件1804班三好学生表h1>
    12. <threegoodstudent :newlist="list">threegoodstudent>
    13. div>
    14. <template id="good3">
    15. <ul>
    16. <li v-for="item in newlist">{{item}}li>
    17. ul>
    18. template>
    19. <script src="js/vue.js">script>
    20. <script>
    21. new Vue({
    22. el: "#app",
    23. data: {
    24. list: ["闫春娜", "牛龙珠", "王笑涵", "刘梓佳", "董新颖", "魏慧娟", "李鑫焱", "王航", "柴尚涛", "刘世龙"]
    25. },
    26. components: {
    27. "threegoodstudent": {
    28. props: ["newlist"],
    29. template: "#good3"
    30. }
    31. }
    32. })
    33. script>
    34. body>
    35. html>

    demo3(自定义组件传参)

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>Documenttitle>
    8. <link rel="stylesheet" href="css/bootstrap.css">
    9. <script src="js/jQuery.min.js">script>
    10. <script src="js/bootstrap.js">script>
    11. head>
    12. <body>
    13. <div id="app">
    14. <h1>脑筋急转弯!h1>
    15. <menus :newlist="list">menus>
    16. div>
    17. <template id="showlist">
    18. <table class="table table-hover table-border">
    19. <tr class="info">
    20. <td>编号td>
    21. <td>问题td>
    22. <td>提示td>
    23. <td>答案td>
    24. tr>
    25. <tr v-for="item in newlist">
    26. <td>{{item.id}}td>
    27. <td>{{item.question}}td>
    28. <td>{{item.title}}td>
    29. <td>{{item.answer}}td>
    30. tr>
    31. table>
    32. template>
    33. <script src="js/vue.js">script>
    34. <script>
    35. new Vue({
    36. el: "#app",
    37. data: {
    38. list: [{
    39. id: 1,
    40. question: "蚂蚁牙齿的颜色",
    41. title: "与歌曲有关",
    42. answer: "o-zone中唱的,蚂蚁牙黑,蚂蚁牙红"
    43. }, {
    44. id: 2,
    45. question: "为什么寒假比暑假短",
    46. title: "物理因素",
    47. answer: "热胀冷缩"
    48. }, {
    49. id: 3,
    50. question: "最残忍的歌词",
    51. title: "爱",
    52. answer: "把你的心我的心串一串"
    53. }]
    54. },
    55. components: {
    56. "menus": {
    57. props: ["newlist"],
    58. template: "#showlist"
    59. }
    60. }
    61. })
    62. script>
    63. body>
    64. html>

    demo4(子父组件传参) 

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>Documenttitle>
    8. <link rel="stylesheet" href="css/bootstrap.css">
    9. <script src="js/jQuery.min.js">script>
    10. <script src="js/bootstrap.js">script>
    11. head>
    12. <body>
    13. <div id="app">
    14. <h1>好孩子亲子系统h1>
    15. <fu-temp :showlist="list">fu-temp>
    16. div>
    17. <template id="fu">
    18. <div>
    19. 简介:<input type="text" v-model="SelectKey" placeholder="请输入搜索关键字"/>
    20. <hr/>
    21. <zi-temp :newlist="filterlist">zi-temp>
    22. div>
    23. template>
    24. <template id="zi">
    25. <div>
    26. <table class="table table-border table-hover" style="text-align: center">
    27. <tr>
    28. <td>编号td>
    29. <td>姓名td>
    30. <td>家长td>
    31. <td>简介td>
    32. tr>
    33. <tr v-for="item in newlist">
    34. <td>{{item.id}}td>
    35. <td>{{item.name}}td>
    36. <td>{{item.fama}}td>
    37. <td><pre>{{item.introduct}}pre>td>
    38. tr>
    39. table>
    40. div>
    41. template>
    42. <script src="js/vue.js">script>
    43. <script>
    44. new Vue({
    45. el: "#app",
    46. data: {
    47. list: [{
    48. id: 1,
    49. name: "李昊天",
    50. fama: "李鑫焱·闫紫瑞",
    51. introduct: "上天下地,如入无人之境,盖一世英雄俾睨天下,无敢不从者。"
    52. }, {
    53. id: 2,
    54. name: "李暖暖",
    55. fama: "李宁·贺子怡",
    56. introduct: "花比你,不温柔。玉比你,也含羞,风雨蝶花间四友,呆打的珂儿都歇在豆蔻梢头!"
    57. }, {
    58. id: 3,
    59. name: "闫崇义",
    60. fama: "闫岩·未知",
    61. introduct: "为把我国建设成富强民主文明的社会主义现代化国家而奋斗终生。"
    62. }, {
    63. id: 4,
    64. name: "徐雅楠",
    65. fama: "徐荣杨·某某某",
    66. introduct: "风雅卓资,形如春风,笑如桃花。眉宇间凝愁,朱唇里吟秋。"
    67. }, {
    68. id: 5,
    69. name: "王雨晴",
    70. fama: "王笑涵·暂无",
    71. introduct: ""
    72. }]
    73. },
    74. //组件
    75. components: {
    76. "fu-temp": {
    77. props: ["showlist"],
    78. data: function() {
    79. return {
    80. SelectKey: "" //用作搜索的参数
    81. }
    82. },
    83. template: "#fu",
    84. components: { //组件
    85. "zi-temp": {
    86. props: ["newlist"],
    87. template: "#zi"
    88. }
    89. },
    90. computed: {
    91. filterlist: function() {
    92. var _this = this;
    93. return _this.showlist.filter(function(o) {
    94. return o.introduct.indexOf(_this.SelectKey) != -1;
    95. });
    96. }
    97. }
    98. }
    99. }
    100. })
    101. script>
    102. body>
    103. html>

    demo4(slot插槽使用)

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>Documenttitle>
    8. head>
    9. <body>
    10. <div id="app">
    11. <h1>三好学生h1>
    12. <good3 :newlist="list">
    13. <template slot="cache" slot-scope="props">
    14. <li>{{props.item}}li>
    15. template>
    16. good3>
    17. div>
    18. <template id="show">
    19. <div>
    20. <slot name="cache" v-for="item in newlist" :item="item">slot>
    21. div>
    22. template>
    23. <script src="js/vue.js">script>
    24. <script>
    25. new Vue({
    26. el: "#app",
    27. data: {
    28. list: ["李鑫焱", "董新颖", "刘梓佳", "王笑涵"]
    29. },
    30. components: {
    31. "good3": {
    32. props: ["newlist"],
    33. template: "#show"
    34. }
    35. }
    36. })
    37. script>
    38. body>
    39. html>

  • 相关阅读:
    计算机组成原理---第七章输入输出系统---I/O系统基本概念,外部系统---选择题
    口袋参谋:如何快速挑选宝贝核心关键词?三种方法,简单有效!
    计算机毕业设计(附源码)python音蕾心动
    纯CSS3流光边框特效
    基于柯西变异的蚁狮优化算法 - 附代码
    阿里云服务器经济型e实例租用价格和CPU性能测评
    服务器在被病毒入侵时快速排出的方法
    opencv c++ 边缘提取
    PACS外围硬件--九五小庞
    【洛谷】P1828 [USACO3.2] 香甜的黄油 Sweet Butter (最短路)
  • 原文地址:https://blog.csdn.net/feng8403000/article/details/126928151