当前位置:   article > 正文

【牛角书】鸿蒙手把手教你做美食大全

【牛角书】鸿蒙手把手教你做美食大全

首先创建一个空项目

然后给项目命名,尽量用英文创建名称。编辑cookbook.hml页面。编辑home.scss页面。编辑cookbook.js。编辑index.hml页面。编辑index.css页面。编辑search.hml。编辑index.js页面。编辑home.js页面。编辑search.js。最总终大概是这样如下图。编辑more.hml。

 

编辑home.hml页面

  1. <element name ="cookbook" src="./cookbook/cookbook"></element>
  2. <element name ="category" src="./category/category"></element>
  3. <element name ="map" src="./map/map"></element>
  4. <element name ="more" src="./more/more"></element>
  5. <div class="container">
  6. <tabs class = "tabs" index="0" vertical="false" onchange="change">
  7. <tab-content class="tab-content" scrollable="{{pageScollable}}">
  8. <cookbook ></cookbook>
  9. <category></category>
  10. <map></map>
  11. <more></more>
  12. </tab-content>
  13. <tab-bar class="tab-bar" mode="fixed">//由于菜单在操作页面的底部,所以tab-bar的部分要放在tab-content的底部
  14. <div class="tabs-item" for="{{(index,tab) in tabs}}">
  15. // <image src="{{currentSelected === index ? tab.tinIcon : tab.icon}}"></image>
  16. <text>
  17. {{tab.title}}
  18. </text>
  19. </div>
  20. </tab-bar>
  21. </tabs>
  22. </div>

编辑home.scss页面

  1. .container {
  2. display: flex;
  3. flex-direction: column;
  4. justify-content: center;
  5. align-items: center;
  6. left: 0px;
  7. top: 0px;
  8. width: 100%;
  9. height: 100%;
  10. }
  11. .title {
  12. font-size: 60px;
  13. text-align: center;
  14. width: 100%;
  15. height: 40%;
  16. margin: 10px;
  17. }
  18. @media screen and (orientation: landscape) {
  19. .title {
  20. font-size: 60px;
  21. }
  22. }
  23. @media screen and (device-type: tablet) and (orientation: landscape) {
  24. .title {
  25. font-size: 100px;
  26. }
  27. }

编辑home.js页面

  1. export default {
  2. data:{
  3. tabs: [
  4. {
  5. id: 'tab1',
  6. title: '美食大全',
  7. icon:'/common/images/cookbook.png',//图标
  8. tintIcon: '/common/images/cookbook-active.png',//图片着色
  9. component: 'cookbook'//切换的时候显示的组件
  10. },
  11. {
  12. id: 'tab2',
  13. title: '分类',
  14. icon:'/common/images/menu.png',
  15. tintIcon: '/common/images/menu-active.png',
  16. component: 'category'
  17. },
  18. {
  19. id: 'tab3',
  20. title: '地图',
  21. icon:'/common/images/location.png',
  22. tintIcon: '/common/images/location-active.png',
  23. component: 'map'
  24. },
  25. {
  26. id: 'tab4',
  27. title: '更多',
  28. icon:'/common/images/more.png',
  29. tintIcon: '/common/images/more-active.png',
  30. component: 'more'
  31. }
  32. ],
  33. currentSelected:0
  34. pageScrollable: true
  35. },
  36. change: function(e) {
  37. this.currentSelected = e.index
  38. },
  39. handlePageScrollable(e){
  40. this.pageScrollable = e.detail
  41. }
  42. }

编辑more.hml

  1. <div class="more-container">
  2. <div class="cb-title">
  3. <text>
  4. 更多
  5. </text>
  6. </div>
  7. <div class="camera-container">
  8. <camera class="camera" ref="camera"></camera>
  9. <div>
  10. <text>
  11. </text>
  12. </div>
  13. <button @click="handleClick" class="btn-takephone">
  14. 拍照
  15. </button>
  16. </div>
  17. </div>

编辑more.js

  1. export default {
  2. data: {
  3. photoUri: '',
  4. checked: true
  5. },
  6. handleClick() {
  7. this.$refs.camera.takePhoto({
  8. success(uri) {
  9. this.photoUri = uri
  10. },
  11. fail(error) {
  12. console.log(error)
  13. }
  14. })
  15. },
  16. handleChange(obj) {
  17. this.$emit('pageScrollable', obj.checked)
  18. }
  19. }

编辑cookbook.hml页面

  1. <element name="cb-swiper"src="./swiper/swiper"></element>
  2. <element name="cb-hotcate"src="./hotcate/hotcate"></element>
  3. <element name="cb-top10"src="./top10/top10"></element>
  4. <element name="cb-serch"src="../../../common/components/serch/serch"></element>
  5. <div class="cb-container">
  6. <div class="cb-title">
  7. <text>
  8. 美食大全
  9. </text>
  10. </div>
  11. <div class="cb-body">
  12. <list>
  13. <list-item class="cb-body-item">
  14. <cb-swiper list="{{list}}"></cb-swiper>
  15. <cb-search from="index"></cb-search>
  16. <cb-hotcate></cb-hotcate>
  17. <cb-top10 list="{{list}}"></cb-top10>
  18. </list-item>
  19. </list>
  20. </div>
  21. </div>

编辑cookbook.js

  1. //@ts-nocheck
  2. import list from '../../common/data/cookbook-list.json';
  3. export default {
  4. data: {
  5. list: []
  6. },
  7. onInit() {
  8. // this.list = list.data
  9. fetch.fetch({
  10. url: 'http//securit.qfjava.cn/hm/cookbook-list.json',
  11. responseType: 'json',
  12. success: res =>{
  13. const result = JSON.parse(res.data)
  14. this.list = result.data
  15. consle.log(result)
  16. }
  17. })
  18. }
  19. }

编辑search.hml

  1. <div class="search-container {{from==='cate' ? 'cate-outer-bg': 'index-outer-bg'}}>
  2. <div class="search-input {{from==='cate' ? 'cate-inner-bg': 'index-inner-bg'}}">
  3. <image src="/common/images/search.png"></image>
  4. <text>想吃什么搜这里</text>
  5. </div>
  6. </div>

编辑search.js

  1. export default {
  2. props: ['from']
  3. }

编辑index.hml页面

  1. <element name="cb-home" src="../home/home"></element>
  2. <div>
  3. <cb-home></cb-home>
  4. </div>

编辑index.css页面

  1. .container {
  2. display: flex;
  3. flex-direction: column;
  4. justify-content: center;
  5. align-items: center;
  6. left: 0px;
  7. top: 0px;
  8. width: 100%;
  9. height: 100%;
  10. }
  11. .title {
  12. font-size: 60px;
  13. text-align: center;
  14. width: 100%;
  15. height: 40%;
  16. margin: 10px;
  17. }
  18. @media screen and (orientation: landscape) {
  19. .title {
  20. font-size: 60px;
  21. }
  22. }
  23. @media screen and (device-type: tablet) and (orientation: landscape) {
  24. .title {
  25. font-size: 100px;
  26. }
  27. }

编辑index.js页面

  1. export default {
  2. data: {
  3. title: ""
  4. },
  5. onInit() {
  6. this.title = this.$t('strings.world');
  7. }
  8. }

最总终大概是这样如下图

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/298993
推荐阅读
相关标签
  

闽ICP备14008679号