Vue初次使用指南

发布于:2023-01-10 ⋅ 阅读:(383) ⋅ 点赞:(0)

启动项目:

 

npm run serve

 

 

终止运行:在终端按ctrl+c,出现如下:

 

 

敲Y,终止

另外,HBuilder有内置终端,视图->内置终端(注:第一次打开会让你下载插件,如果插件下载失败,记得选择以管理员身份运行,就可以下载成功啦)

和cmd一样

 

 

然后就可以在这里编辑

 

组件之间的关系: index.html--(main.js)-->App.vue->HelloWorld.vue

 

新建.vue(注:<template>里只能有一个div)

 

 一个例子:

  

 

<template>
  <div><p>组件1</p></div>
</template>

<script>
</script>

<style scoped>
  div {
    background-color: black;
    width:100%;
    height: 100px;
  }
</style>

<template>
  <div>
    <p>组件2</p>
    </div>
</template>

<script>
</script>

<style scoped>
  div {
    background-color: green;
    width:100%;
    height: 100px;
  }
</style>

<template>
  <div>
    <p>{{info}}</p>
    <button @click="show()">显示数据</button>
    <c1></c1>
    <c2></c2>
  </div>
</template>

<script>
  import c1 from '@/components/Child1.vue'
  import c2 from '@/components/Child2.vue'
  
  export default {
    components:{
      c1,
      c2
    },
    data(){
      return {
        info: 'Hello World!'
      }
    },
    methods:{
      show(){
        alert(this.info);
      }
    }
  }
</script>

<style>
  div p {
    color: red;
  }
</style>

 

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到