# head

head 模块提供原生Native的导航条按钮功能。

注意head模块目前只在我们JSNative app端支持,web端不支持

# API

# setTitle(options, callback[options])

设置JSNative页面title

# 参数

  • options {object}:选项参数对象
    • title{string}:title字符串

# 示例

<template>
      <div>
        <text>Hello World!</text>
    </div> 
</template>

<script>
  var head = Light.requireModule('head');
  var modal =Light.requireModule('modal');
  module.exports = {
    created:function(){
      head.setTitle({title:"head模块"});
    }
  }
</script>

# setLeftItem(options, callback[options])

设置JSNative页面导航条左侧按钮,且最多只能添加两个,添加第三个按钮则会覆盖第二个按钮

# 参数

  • options {object}:选项参数对象
    • title{string}:button显示的字符串
    • icon{ string }:button的图标,这个优先级比title高,图标需要放在gmu目录下的gmu_icon文件夹下
  • callback {function}:点击按钮事件

# 示例

<template>
      <div>
        <text>Hello World!</text>
    </div> 
</template>

<script>
  var header = Light.requireModule('head');
  var modal =Light.requireModule('modal');
  module.exports = {
    created:function(){
      header.setTitle({title:"head模块"});

      header.setLeftItem({title:"左边1"},function(res){
         modal.toast({ message: '左边1点击事件'});
      });
      header.setRightItem({title:"右边1"},function(){
         modal.toast({ message: '右边1点击事件'});
      });
    }
  }
</script>

# setRightItem(options, callback[options])

设置JSNative页面导航条右侧按钮,且最多只能添加两个,添加第三个按钮则会覆盖第二个按钮

# 参数

  • options {object}:选项参数对象
    • title{string}:button显示的字符串
    • icon{ string }:button的图标,这个优先级比title高,图标需要放在gmu目录下的gmu_icon文件夹下
  • callback {function}:点击按钮事件

# 示例

<template>
      <div>
        <text>Hello World!</text>
    </div> 
</template>

<script>
  var header = Light.requireModule('head');
  var modal =Light.requireModule('modal');
  module.exports = {
    created:function(){
      header.setTitle({title:"head模块"});

      header.setLeftItem({title:"左边1"},function(res){
         modal.toast({ message: '左边1点击事件'});
      });
      header.setRightItem({title:"右边1"},function(){
         modal.toast({ message: '右边1点击事件'});
      });
    }
  }
</script>

# removeButton (options, callback[options])

设置JSNative页面title

# 参数

  • options {object}:选项参数对象
    • position{string}:按钮位置 left或者right
  • callback {function}:执行完该操作后的回调函数,返回的信息在callback中,格式参考如下:
{
  result: success,
}

# 示例

<template>
      <div>
        <text>Hello World!</text>
         <text class="item" @click="onClick('header.removeLeftButton')">removeLeftButton</text>
         
        <text class="item" @click="onClick('header.removeRightButton')">removeRightButton</text>
    </div> 
</template>

<script>
  var header = Light.requireModule('head');
  var modal =Light.requireModule('modal');
  module.exports = {
    created:function(){
      header.setTitle({title:"head模块"});

      header.setLeftItem({title:"左边1"},function(res){
         modal.toast({ message: '左边1点击事件'});
      });
      header.setRightItem({title:"右边1"},function(){
         modal.toast({ message: '右边1点击事件'});
      });
    },
    methods:{
      onClick:function(action){
        if (action.indexOf("header.remove")!=-1){
             var options={};
             options.position="right";
             if(action=="header.removeLeftButton"){
                options.position="left";
             }
             header.removeButton(options,function(res){
                 modal.toast({ message: JSON.stringify(res)});
             });
        }
      }
    }
  }
</script>

# back

返回上一页,该接口将要废弃,不推荐使用。若要返回上一页请使用navigator模块中pop方法。

# 示例

<template>
      <div>
        <text>Hello World!</text>
    </div> 
</template>

<script>
  var head = Light.requireModule('head');
  module.exports = {
    created:function(){
      head.back(});
    }
  }
</script>